0

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?

  • Can you provide html code? How do you know that first locator is correct? – tugo Apr 28 at 7:11
  • because it matched with one element..i will provide the screenshot above... I am trying to click on the link which is not visible initially...So, I used moveToElement() and from the fly-out menu, tried to click the link...This is myntra.com – Albin K S Apr 28 at 7:15
  • I asked that question because your xpath looks strange. I would tried something like //a[@class='desktop-categoryLink'][@data-reactid='30']. Moreover maybe better is to use href attribute? – tugo Apr 28 at 7:26
  • I tried this //a[@class='desktop-categoryLink'][@data-reactid='30'].. But now it is throwing "org.openqa.selenium.ElementNotVisibleException: element not interactable" exception – Albin K S Apr 28 at 7:38
  • Ok, that can mean that there is multiple elements that match your search and some are hidden. Please try to use //a[@href='/men-tshirts'] – tugo Apr 28 at 7:47
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.