【发布时间】:2014-04-08 06:15:47
【问题描述】:
<table width="100%" cellspacing="1" cellpadding="0">
<tbody>
<tr>
<tr>
<tr>
<td class="tblForeground">
<table id="defaultaccess" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td valign="TOP" align="LEFT" scope="rowgroup">
<img width="12" height="12" border="0" alt="" src="/img/8space.gif">
<img width="16" height="16" border="0" alt="Public Access" src="/img/publicaccess.gif">
<a target="info" href="/Livelink/livelink.exe?func=ll&objAction=EditAcl&objId=9388&id=9388&rightId=-1&permType=3&nextURL=%2FLivelink%2Flivelink%2Eexe%3Ffunc%3Dll%26objid%3D2000%26objAction%3Dbrowse%26sort%3Dname">Public Access</a>
在上面的表格 html 代码中,我想找到带有文本“Public Acess”的“a”标签。但是当我使用下面的代码时,它会显示一个错误,因为我无法找到该元素。下面是代码:
WebElement element1 = driver.findElement(By.className("tblForeground"));
List<WebElement> list1 = element.findElements(By.id("defaultaccess"));
for (int i = 0; i < list1.size(); i++) {
if (list1.get(i).findElement(By.tagName("a")).getText().equals("Public Access")) {
list1.get(i).findElement(By.tagName("a")).click();
break;
}
}
您能帮我找到上表中的特定元素吗? 提前致谢。
【问题讨论】:
-
你试过用selenium ide来记录定位器吗?
-
是的,我试过了,但它没有得到在 selenium ide 中它只显示断言标题