【发布时间】:2017-04-30 22:44:51
【问题描述】:
我正在尝试单击数据单元格 td 中的复选框,但每次我得到:
org.openqa.selenium.ElementNotVisibleException
例外, 问题是元素已启用但不可见。
以下是页面来源:
<table id='table1'>
<thead></thead>
<tbody>
<tr>
<td>
<input id='id1' class='class' type='checkbox'>
<label for='chk1'>
:: before
</label>
</td>
</tr>
<tr>
<td>
<input id='id2' class='class' type='checkbox'>
<label for='chk2'>
:: before
</label>
</td>
</tr>
<tr>
<td>
<input id='id3' class='class' type='checkbox'>
<label for='chk3'>
:: before
</label>
</td>
</tr>
</tbody>
</table>
但下面的代码可以正常工作并返回。
System.out.println("isDisplayed()"+ td_lblcollection.get(0).isDisplayed()); --> False
System.out.println("isEnabled()"+td_lblcollection.get(0).isEnabled()); --> True
System.out.println("isSelected()"+td_lblcollection.get(0).isSelected()); --> False
手动复选框可见且可以选择,但 IsDisplayed 为 false 并引发元素不可见异常。
尝试了以下所有方法,但一切都失败了。定位器很好。
定位器:
@FindBy(xpath = "//*[@id='table1']/tbody/tr")
List<WebElement> tblLookupSites;
方法1:在表中循环
for (WebElement trElement : tblLookupSites) {
List<WebElement> td_collection = trElement.findElements(By.xpath("td"));
for (WebElement tdElement : td_collection) {
List<WebElement> td_lblcollection =tdElement.findElements(By.xpath("label"));
td_lblcollection.get(0).click();
}
}
方法2:在表中循环
for (WebElement trElement : tblLookupSites) {
List<WebElement> td_collection = trElement.findElements(By.xpath("td"));
for (WebElement tdElement : td_collection) {
List<WebElement> td_lblcollection =tdElement.findElements(By.xpath("input"));
td_lblcollection.get(0).click();
}
}
方法3:在表中循环
for (WebElement trElement : tblLookupSites) {
List<WebElement> td_collection = trElement.findElements(By.xpath("td"));
for (WebElement tdElement : td_collection) {
List<WebElement> td_lblcollection =tdElement.findElements(By.id("id1"));
td_lblcollection.get(0).click();
}
}
请建议如何点击此复选框。
UI 是使用 vue.js 创建的。
【问题讨论】:
标签: java selenium checkbox html-table vue.js