0

I've a question, how can I capture the xpath in the case below?

I tried this:

driver.findElement(By.xpath("//*[@id='L2_auto_8']/div/a[1]")); 

and I tried:

driver.findElement(By.xpath(//a[@href='/principal.aspx']));

but I received this error: org.openqa.selenium.NoSuchElementException

Screenshots 1
Screenshots 2
Screenshots 3

  • Do your xpaths work in browser dev-tools? And whether your test reachs the page you're facing an issue at? – Alexey R. Mar 15 '18 at 11:25
  • yes, look at my screenschot [3] , when i search xpath in dev-tools – skape Mar 15 '18 at 14:30
0

I'm not sure why your first xpath fails, it looks okay to me, but your second one fails because you're looking for an exact match, but only showing part of the URL and in your example, at least, is missing quotes.

WebElement lnk = driver.findElement(By.xpath("//a[ends-with(@href,'/principal.aspx')]"));
0

Try this Xpath. Xpath by using the text in the a tag

"(//a[contains(text(),'Dados Pessoais')])[give the occurrence of this text]"

for example if this xpath matches with multiple elements then give the number where it matches the exact. If it matches with the 4th element then give as below

"(//a[contains(text(),'Dados Pessoais')])[4]".

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.