CodeLover CodeLover - 7 months ago 21
Ruby Question

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!

Answer

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

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