Reputation: 559
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?
Upvotes: 2
Views: 2478
Reputation: 9058
Try this. You need to start with a period at the beginning.
By.xpath("(.//td[@class=\"spreadsheet\"])[24]")
Upvotes: 6