2

I want to select several elements on a site and iterate through them. Of these elements I want to find nested elements with xpath.

List<WebElement> elements = driver.findElements(By.className("aagrRow"));
for(WebElement we: elements){ 
    System.out.println(we.findElement(By.xpath("(//td[@class=\"spreadsheet\"])[24]")).getText());
}

The problem I have is that xpath doesnt seem to search inside the we-element but from the root of the document. What can I do?

1 Answer 1

6

Try this. You need to start with a period at the beginning.

By.xpath("(.//td[@class=\"spreadsheet\"])[24]")

https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#findElements-org.openqa.selenium.By-

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.