I am trying to figure out how to know which is the position of current node under it parent, currently I am using selenium and most of the time I use Xpath. This is because I want to extract all the columns of a table In this example the number of columns are dynamically generated
<tabe>
<tr>
<td>23</td>
<td>42</td>
<td>31</td>
</tr>
<tr>
<td>13</td>
<td>21</td>
<td>32</td>
</tr>
</table>
So lets say that I need the second colunm (42 and 21), but since the the content is dynamically generated I don't know if it is the second colum I only know that I want the colum with the number 42. So with selenium I get the 42 easily. Bu I need the position of it td.
I have thought in an algorithm that might be complex and slow. Basically something like:
- Get the html code under current
- Get the parent of current node
- Iterate (while counting) got an the parent and compare each child inner code with the one that I found.
- Some other validations that I need to think
- When I found it that's the colum
That algorithm have some issues like "What if there are 2 elements with the same inner code" and as I mentioned that might be slow and don't let me start when I start considering the Row and colum span (currently I just need the position in the current row).
So there is a easier way to do this? Some selenium function that I don't know or maybe a way to get it though XPath?
Thanks :)