rkrox 907
rkrox 907

Reputation: 127

Python selenium find following sibling

I am trying to grab the next sibling

<tr id="12345">
   <td>
      <a id="6789">text1</a>
   </td>
   <td>
      text2
   </td>
   <td>
      text3
   </td>
</tr>

i was able to extract 'text1' by using this code:

driver.find_elements_by_xpath("//a[contains(@id, '6789')]")

i tried extracting 'text2' with this code:

driver.find_element_by_xpath(
    "//a[@id='6789']/following-sibling::td")

but i got 'no such element' error

How can i extract 'text2' and 'text3'

Upvotes: 0

Views: 204

Answers (1)

supputuri
supputuri

Reputation: 14135

Use this xpath instead.

//a[@id='6789']/parent::td/following-sibling::td

Reason why your xpath did not worked: The td is not a sibling to a.

Upvotes: 1

Related Questions