0

I'm using selenium-webdriver and want to get Text value by using Keyword as a start point.

<tr>...</tr>
<tr>...</tr>
<tr><td><font>Keyword</font></td></tr>
<tr>...</tr>
<tr>...</tr>
<tr><td>Text</td></tr>
<tr>...</tr>
<tr>...</tr>

I can get Keyword element like this driver.find_element(:xpath, "//tr/td/font[text()='Keyword']"), but I have no idea how to get Text element from that Keyword.

Text is always different and the Number of tr elements are undefined. But between Keyword and Text there are always two tr elements.

How can I get the value by using xpath?

ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

0

This xpath should get you the node you want:

//tr/td/font[contains(text(), 'Keyword')]/../../following-sibling::tr[3]/td
Richard
  • 8,961
  • 3
  • 38
  • 47