我试图
以下是表格HTML的两行:
<tr type="row" adr="3" tag="" id="x:442163216.17:adr:3:tag:" class="ig_ListAlt igg_ListAlt IG_Fields_Row ">
<td wlkd="1" type="cell" idx="0" adr="0" class="ig9a63765d ">1</td>
<td class="ig9a63765e ">0</td>
<td class="ig9a63765f ">true</td>
<td class="ig9a637660 ">true</td>
<td class="ig9a637661 ">false</td>
<td class="ig9a637662 ">true</td>
<td class="ig9a637663 "></td>
<td class="ig9a637664 ">true</td>
<td type="cell" adr="8" idx="8" class="IG_Fields_Cell IG_Cell_Selectable IG_Cell_Center ">
<img id="ctl00_ctl00_ctl00_Main_Main_Main_grdFields_it8_3_imgCheckVisible" src="Images/GreenCheckmarkIcon16x16.png" style="visibility:visible;">
</td>
<td class="ig9a637665 ">false</td>
<td type="cell" adr="10" idx="10" class="IG_Fields_Cell IG_Cell_Selectable IG_Cell_Center ">
<img id="ctl00_ctl00_ctl00_Main_Main_Main_grdFields_it10_3_imgCheckRequired" src="Images/GreenCheckmarkIcon16x16.png" style="visibility:hidden;">
</td>
<td class="ig9a637666 ">Loan Type</td>
<td tabindex="-1" wlkd="1" type="cell" adr="12" idx="12" class="IG_Field_Field_Name ">Loan Type</td>
<td type="cell" adr="13" idx="13" class="IG_Fields_Cell ">Loan Type</td>
<td type="cell" adr="14" idx="14" class="IG_Fields_Cell "></td>
<td type="cell" adr="15" idx="15" class="IG_Fields_Cell IG_Cell_Center ">
<a href="javascript:ShowCheckboxGroupPopup();"><img src="/images/Configure-Icon-16x15.png" alt="" class="Configure"></a>
</td>
<td class="ig9a637667 ">false</td>
<td class="ig9a637668 "></td>
<td class="ig9a637669 ">false</td>
</tr>
<tr class=" " type="row" adr="2" tag="" id="x:442163216.17:adr:2:tag:">
<td wlkd="1" type="cell" idx="0" adr="0" class="ig9a63765d ">45</td>
<td class="ig9a63765e ">0</td>
<td class="ig9a63765f ">true</td>
<td wlkd="1" type="cell" idx="3" adr="3" class="ig9a637660 ">true</td>
<td class="ig9a637661 ">false</td>
<td class="ig9a637662 ">true</td>
<td class="ig9a637663 "></td>
<td class="ig9a637664 ">false</td>
<td type="cell" adr="8" idx="8" class="IG_Fields_Cell IG_Cell_Selectable IG_Cell_Center ">
<img id="ctl00_ctl00_ctl00_Main_Main_Main_grdFields_it8_2_imgCheckVisible" src="Images/GreenCheckmarkIcon16x16.png" style="visibility:hidden;">
</td>
<td wlkd="1" type="cell" idx="9" adr="9" class="ig9a637665 ">false</td>
<td tabindex="-1" wlkd="1" type="cell" adr="10" idx="10" class="IG_Fields_Cell IG_Cell_Selectable IG_Cell_Center ">
<img id="ctl00_ctl00_ctl00_Main_Main_Main_grdFields_it10_2_imgCheckRequired" src="Images/GreenCheckmarkIcon16x16.png" style="visibility: hidden;">
</td>
<td class="ig9a637666 ">Intent to Proceed Received Date</td>
<td tabindex="-1" wlkd="1" type="cell" adr="12" idx="12" class="IG_Field_Field_Name ">Intent to Proceed Received Date</td>
<td type="cell" adr="13" idx="13" class="IG_Fields_Cell ">Intent to Proceed Received Date</td>
<td type="cell" adr="14" idx="14" class="IG_Fields_Cell "></td>
<td type="cell" adr="15" idx="15" class="IG_Fields_Cell IG_Cell_Center ">
<a href="javascript:ShowITPTracking();"><img src="/images/Configure-Icon-16x15.png" alt="" class="Configure"></a>
</td>
<td class="ig9a637667 ">false</td>
<td class="ig9a637668 "></td>
<td class="ig9a637669 ">false</td>
</tr>
我正在获取具有adr = 8属性的元素列表,如果隐藏了复选标记图标,则单击该列:
List<WebElement> showColumn = driver.findElements(By.cssSelector("td[class='IG_Fields_Cell IG_Cell_Selectable IG_Cell_Center'][adr='8']"));
for(WebElement show : showColumn)
{
System.out.println("Found the element");
// If not selected, select it
if (show.findElement(By.tagName("img")).getAttribute("style").contains("hidden"))
{
show.click();
}
}
但是,它永远不会进入for循环。如果在创建元素列表时删除[adr =&#39; 8&#39;]约束,则会进入每个单元格。我只需要adr = 8列......
--- --- UPDATE
原来,&#39; idx&#39;和&#39; adr&#39;在元素悬停之前,属性不会出现。我将尝试使用robot类将鼠标悬停在该类的所有元素上,然后搜索adr属性。不确定会有多可靠。