Locator Issue regarding multiple attribute



  • enter image description hereI've located an element correctly by using the following XPath...

    //a[@class=\"desktop-categoryLink\"][@data-reactid="30"]
    

    But when I paste this in my eclipse it looks like below...

    driver.findElement(By.xpath("//a[@class=\"desktop-categoryLink\"][@data-reactid=\"30\"]")).click();
    

    Then I removed the two '\' before and after 30..then it shows an error like "The left-hand side of an assignment must be a variable"..Guys how can I resolve this?



  • Then I removed the two '\' before and after 30..then it shows an error like "The left-hand side of an assignment must be a variable"..Guys how can I resolve this?

    You cannot remove the two '\' because that are escape characters for the double quotes. When you remove the backslash you are creating two strings instead of one. String one will consist of "//a[@class=\"desktop-categoryLink\"][@data-reactid=" while string two only has the bracket "]". With the 30 being an int in the middle.

    See this answer to learn more about escape characters in strings



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2