<tr> <td>Blah!</td> <td>X</td> <!-- TR containing X --> <td>Woot!</td> </tr> <tr> <td>Useful Data, contents unknown</td> <!-- Select this TR --> </tr> <tr> <td>Useless data</td> <!-- Don't select this or any subsequent TR --> </tr> <tr> <td>More crap I don't want</td> </tr> <tr> <td>X</td> <!-- Another X --> </tr> <tr> <td>Useful</td> <!-- Do select this one, since previous has X --> </tr>
What XPath would return the <tr>
immediately following the <tr>
that contains X?
//div[@class='content'][2] means: Select all elements called div from anywhere in the document, but only the ones that have a class attribute whose value is equal to "content". Of those selected nodes, only keep those which are the second div[@class = 'content'] element of their parent.
import.io - Xpath to select next parent of the current node - Stack Overflow.
The < tr > tag in the table indicates the rows in the table and that tag is used to get information about the number of rows in it. Number of columns of the web table in Selenium are calculated using XPath (//*[@id='customers']/tbody/tr[2]/td).
XPath stands for XML Path Language. It uses a non-XML syntax to provide a flexible way of addressing (pointing to) different parts of an XML document. It can also be used to test addressed nodes within a document to determine whether they match a pattern or not.
ChaosPandion's and Martin v. Löwis's answers both work for the sample you give, but if you are asking for the next tr, then presumably in some cases there are further tr elements in same table. In which case, the answers will give all the following or following-sibling tr elements.
Also going by the headline question rather than the sample, the xpath should probably allow for the X being in a th cell instead of td. And I'm guessing that you'd only want the following tr if it is in the same parent (thead, tbody, tfoot).
So I'd go for
//tr[* = 'X']/following-sibling::tr[1]
This should work.
tr[td/text() = 'X']/following-sibling::node()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With