Home > Enterprise >  Selenium Webdriver - Relative xpath
Selenium Webdriver - Relative xpath

Time:06-24

I am a beginner in Selenium. I do not have any hands on experience in it. Last month I had enrolled for a Selenium beginner to advanced course where I have few activities where I can do hands on.

I am stuck at a certain place. Let me explain my issue.

This is the activity description:

RelativeXpathLocator

URL: http://webapps.tekstac.com/Shopify/

Test Procedure:

  1. Use the template code.
  2. Don't make any changes in DriverSetup file.
  3. Only in the suggested section add the code to,
  4. Invoke the driver using getWebDriver() method defined in DriverSetup()
  5. Identify the web element of the value 'SivaKumar' using xpath locator and return it.
  6. Using the same web element, get the text and return it.

The code that I wrote for this:

//Add required imports
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class RelativeXpathLocator    //DO NOT Change the class Name
{
    static String baseUrl = "http://webapps.tekstac.com/Shopify/";
    public WebDriver createDriver()    //DO NOT change the method signature
    {
        DriverSetup ds = new DriverSetup();
        return ds.getWebDriver();
       //Implement code to create Driver from DriverSetup and return it
    }
    public WebElement getRelativeXpathLocator(WebDriver driver)//DO NOT change the method signature
    {
        WebElement l = driver.findElement(By.xpath("//*[@id="tbrow"]/td[3]"));
        return (l);
       /*Replace this comment by the code statement to get the Web element */
       /*Find and return the element */
       
    }
    public String getName(WebElement element)//DO NOT change the method signature
    {
        //Get the attribute value from the element and return it
    }

    public static void main(String[] args){
        RelativeXpathLocator pl=new RelativeXpathLocator();
        //Add required code
        
    }
}

Note: Stuck at Public Webelement getRelativeXpathLocator

Now after I typed the code and complied to check if it threw any error, I was able to see expect ")" ";" errors in the xpath line.

I've been struggling for hours to get this to work but in vain.

Please advice.

Thanks.

CodePudding user response:

The error is double quotation " in xpath , so change the xpath

From

driver.findElement(By.xpath("//*[@id="tbrow"]/td[3]"));

To

driver.findElement(By.xpath("//*[@id='tbrow']/td[3]"));
  • Related