All the samples of findElement(By.xpath) I Have observed hunt the entire site, e.g.
WebElement td = driver.findElement(By.xpath(“//td”));
What I would like to realize is this:
WebElement tr = … // find a particular table row (no problem here)
WebElement td = tr.findElement(By.xpath(“/td”)); // Doesn’t work!
I have also tried other versions without fortune: “toronto-Dominion”, “kid::td”
Utilizing “//td” discovers the first matching node in all site, i.e. maybe not limited to my tr. S O it is seeming like when you findElement by xpath, the WebElement where you c all findElement() matters for nothing.
Might it be possible to extent findElement(By.xpath) to your specific WebElement?
(I am utilizing Opera, in the event it issues.)
PLEASE NOTICE: By.xpath(“//td”) is only an illustration. I am maybe not seeking for alternate methods of reaching exactly the same point. The query is simply about attempting to determine whether foo.findElement() requires any notice of foo when utilized with a By.xpath selector.
Centered on ZzZ’s response I believe the problem is the questions you’re attempting are absolute instead of relative. By utilizing a beginning / you push complete investigation. As an alternative utilize the label title as ZzZ proposed, ./ or .//.
Try the XPath doctors under “Place Route Phrase”
I also went into this problem and invested lots of time attempting to determine the work around. And that is what I determined:
WebElement td = tr.findElement(By.xpath(“td”));
I believe this may be a bug in the way in which that Selenium2 utilizes xpath. Nevertheless, I consider I Have effectively restricted the range utilizing “::ancestor” before.
In almost any occasion, maybe you have tried using CSS Selectors to resolve this? Is an alternative for you? Try this:
This must get the job done and is the same of what you attempted initially:
what I m comprehending that u need to recover a specific td from a tr, therefore here is a bit it is possible to attempt it with your signal to locate 3rd td.
WebElement tr=//…find a particular table row
List<WebElement> columns = tr.findElements(By.tagName(“td”));
Iterator<WebElement> j = columns.iterator();
WebElement column = j.next();
If you just need to locate the child components of the tr work with a relative path not a complete.
This should function:
int index = 3;
List<WebElement> tds = tr.findElements(By.xpath(“.//td”));