Currently Browsing

Posts Tagged ‘ table ’

How to select an element from table if there is no ID

When we want to select a value from a table but the element doesn’t have id or other identification, we can use the other cells of the table to identify the value.

For example:

Table

<table id="business_marketData_items" summary="Current market values for major international indexes">
<tbody>
<tr>
<td><a href="http://www.bbc.co.uk/news/business/market_data/stockmarket/2/">Dow Jones</a></td>
<td>14828.78</td>
<td><span>+</span></td>
<td>116.23</td>
<td>0.72%</td>
</tr>
<tr>
<td><a href="http://www.bbc.co.uk/news/business/market_data/stockmarket/12122/"> Nasdaq</a></td>
<td>3312.14</td>
<td><span>+</span></td>
<td>32.88</td>
<td>0.85%</td>
</tr>
</tbody>
</table>

There is a table with stock market data and we want to get the value of the percentage of change (the last column). The percentage doesn’t have any identification, but we know the name of the stock market. For example we choose Dow Jones and the desired value is 0.72%.

How to get the value?