我在将元素定位到这样的网页中时遇到了一些问题:
<tr id="filter100" style="...." idx=0
<td>
<div onclick=... style=...
<table dir = "fil">
<tbody>
<tr>
<td>
<img id="imgFil100_1" src="//path..."
<td>
<td>
<img id="imgFil100_2" src="//path..."
<td>
<td>
<img id="imgFil100_3" src="//path..."
<td>
而且我有很多这样的按钮“filterXXX”。我如何找到它们并单击它们。
我写了这段代码
List<WebElement> lc = driver.findElements(By.cssSelector("table[id*='imgFil']"));
for (int i = 0; i <= lc.size(); i++) {
lc.get(i).click();}
顺便说一句,对不起我的英语。
最佳答案
List<WebElement> lc = driver.findElements(By.cssSelector("table[id*='filter']"));
for (WebElement row : lc) {
List<WebElement> images = row.findElements(By.tagName("img"));
for (WebElement image : images) {
image.click();
}
}
关于java - Selenium Java 如何定位元素问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25993500/