html - XPath parent based on several children -
how select select parent <tr> elements containing ccc , ddd in it, , no others?
i.e. xml below:
<table> <tr> <td>aaa</td> <td>bbb</td> <td>select</td> </tr> <tr> <td>ddd</td> <td>ccc</td> <td>select</td> </tr> <tr> <td>ccc</td> <td>ddd</td> <td>select</td> </tr> <tr> <td>aaa</td> <td>ccc</td> <td>select</td> </tr> </table> select row:
<tr> <td>ccc</td> <td>ddd</td> <td>select</td> </tr> alternatively, how select 3rd td (with select written in it) on same row of td's ccc & ddd?
an xpath look contains several location steps. each step creates context either predicate (within [...]) or next step. last step contains result set selected. can apply 1 or more predicates in step, cut down set.
this look selects tr element contains td element string value of aaa , td element string value of bbb.
//tr[td='aaa' , td='bbb'] this look select set containing 2 td nodes (<td>select</td>) sec , 3rd <tr>s (the ones have td='ccc' , td='ddd':
//tr[td='ccc' , td='ddd']/td[3] instead of using and can stack predicates. each predicate reduces result set creating context in next predicate operates. has same effect above expression:
//tr[td='ccc'][td='ddd']/td[3] html xml selenium xpath
No comments:
Post a Comment