0

我在将元素定位到这样的网页中时遇到了一些问题:

<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();}

顺便说一句,对不起我的英语。

4

1 回答 1

0
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();
  }
}
于 2014-09-24T10:02:14.143 回答