Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath Element that contains 2 children that each match a specific text

Tags:

selenium

xpath

I'm using Selenium to target certain elements on a page.

I have a table that looks like this

<table>
    <tbody>
         <tr>
             <td>Text1</td>
             <td>Text2</td>
         </tr>
         ...
    </tbody>
</table>

Each <tr> element matches this pattern. I want to pass in two strings, text1 & text2, and find the row element whose two cells match text1 and text2, in that order. I'm assuming XPath is the way to go, I'm just not really sure how to write this case, if it's possible.

like image 473
allie Avatar asked Nov 16 '25 16:11

allie


1 Answers

predicates can be combined:

//tr[td[1]="Text1" and td[2]="Text2"]
like image 96
tdrury Avatar answered Nov 18 '25 21:11

tdrury



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!