CodeLover
CodeLover

Reputation: 1074

How to use "selenium-webdriver-xpath" to get the text value from <td>?

Find the below html code:

<table id="supplier_list_data" cellspacing="1" cellpadding="0" class="data">
   <tr class="rowLight">
      <td class="extraWidthSmall">
         <a href="/aems/do.list">  Cdata </a>
      </td>
      <td class="extraWidthSmall">
         <a href="/aem/do.list">  xyz </a>
      </td>
      <td class="extraWidthSmall">
         <a href="/bem/do.list">  ppm </a>
      </td>
   </tr>
</table>

Now using xpath how to get the value xyz (means always the second "<td>") . Give me an idea please!

Upvotes: 0

Views: 3848

Answers (1)

Jens Erat
Jens Erat

Reputation: 38722

Try //tr/td[2]/data().

//tr/td selects all <td/> elements, [2] the second result inside each <tr/> and data() returns their contents.

Upvotes: 1

Related Questions