我用下面的代碼來檢索,我想在硒選擇行:找到一個TR標籤的複選框,並在硒(JAVA)選擇它
WebElement row = driver.findElement(By.xpath("//tr[contains(.,'prod1')]"));
其結果是,我得到以下列:
<th width="18px">
<input class="selectedProducts" id="checkbox-37640" onclick="markedProductsHandler.toggleMarkProduct(this,37640)" type="checkbox">
</th>
<th style="white-space:nowrap; width:573px;" align="left">
<a class="maxTextSize" style="width:530px" href="product.html?id=37640&rm7zz5c=ZBOeBCOAs">aa prod1</a>
</th>
<th style="white-space:nowrap;" align="right" width="140px">
<a href="product-edit.html?id=37640&rm7zz5c=ZBOeBCOAs"><img src="_images/icons/pencil.png?rm7zz5c=ZBOeBCOAs" title="Edit"></a>
<input name="favoriteid" class="favoriteAction" value="37640" type="hidden">
<input name="favoriteaction" class="favoriteAction" value="add" type="hidden">
<a href="javascript:" onclick="onFavoriteAction(this)">
<img src="_images/icons/star_grey.png?rm7zz5c=ZBOeBCOAs" alt="Watch product" title="Watch product">
</a>
<form action="product-pdf.html?rm7zz5c=ZBOeBCOAs" method="post">
<input name="export" value="pdf" type="hidden">
<input name="id" value="37640" type="hidden">
<a href="javascript:" onclick="javascript: $(this).parent().submit();"><img src="_images/icons/page_white_acrobat.png?rm7zz5c=ZBOeBCOAs" title="Download as PDF"></a>
</form>
</th>
現在我想請選中該複選框:
row.findElement(By.xpath("//input[@type='checkbox']")).click();
,但我得到了以下錯誤:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
有人能幫助我嗎?謝謝。
根據例外情況,它好像隱藏了複選框。對於'selectedProducts'類,有沒有像'visibility:hidden;'或'display:none'這樣的風格?https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium /ElementNotVisibleException.java – osigge
你能告訴我們'row.findElement(By.xpath(「//輸入[@ type ='checkbox']」))。isDisplayed()'?的結果嗎? +嘗試添加服務員等待,直到複選框將變得可見 – drets
嗨,結果是假的 –