开发者

How to get the 1st column for all rows within a table using Selenium java API

开发者 https://www.devze.com 2023-03-03 13:34 出处:网络
I got a table with <tr> data as: <tr class=\"iceDatTblRow1\" id=\"body-subview:myMainPage:MainTabs:0:dataTable:0\">

I got a table with <tr> data as:

<tr class="iceDatTblRow1" id="body-subview:myMainPage:MainTabs:0:dataTable:0">
 <td class="iceDatTblCol1"><span class="iceOutTxt" id="body-
   subview:myMainPage:MainTabs:0:dataTable:0:j_idt252">Data that I want</span>
 </td>
</tr>

for some 开发者_Go百科reason, i can't seem to locate the <td> with id attribute within it... please share your expertise - thanks,


I don't know about Selenium but there are many XPath solutions here. A few examples:

  • span everywhere:
//span[@id='body-subview:myMainPage:MainTabs:0:dataTable:0:j_idt252']
  • span only inside td:
//td/span[@id='body-subview:myMainPage:MainTabs:0:dataTable:0:j_idt252']


If your requirement is to get all the first column for all rows with Selenium and Xpath then you can try this code:

String tdLocator="//tr"
int count = selenium.getXpathCount(tdLocator)
for(int i = 1;i<=count;i++)
{
get to td by using //tr[i]/td[0]
}

If you have a table ID then you can also use

selenium.getTable("table_id.[rownumber].[colnumber])
0

精彩评论

暂无评论...
验证码 换一张
取 消