c# - How do I know the node position under parent with selenium? -


i trying figure out how know position of current node under parent, using selenium , of time use xpath. because want extract columns of table in example number of columns 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 need second colunm (42 , 21), since the content dynamically generated don't know if second colum know want colum number 42. selenium 42 easily. bu need position of td.

i have thought in algorithm might complex , slow. like:

  1. get html code under current
  2. get parent of current node
  3. iterate (while counting) got parent , compare each child inner code 1 found.
  4. some other validations need think
  5. when found that's colum

that algorithm have issues "what if there 2 elements same inner code" , mentioned might slow , don't let me start when start considering row , colum span (currently need position in current row).

so there easier way this? selenium function don't know or maybe way though xpath?

thanks :)

playing around little xpath came following query;

//tr[2]/td[position()=count(//tr[1]/td[.='42']/preceding-sibling::*) + 1] 

this give relative positioned "td" of 2nd "tr" selection of text found in "td" of 1st "tr".

this based on find position of node using xpath


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -