簡體   English   中英

Selenium Java元素如何定位?

[英]Selenium Java How locating element issue?

我在將元素定位到這樣的網頁時遇到一些問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM