當我使用列出的方法來查看某個元素是否在頁面上可見時,我收到一個異常,指出它的無法使用指定的定位器查找元素。硒方法visibilityOf - 似乎沒有工作?
任何想法,有沒有人遇到過這個問題,甚至有更好的方法?
public boolean isElementPresentByWebElement(WebElement element) {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).withTimeout(15, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
for (int i = 0; i < 2; i++) {
try {
fluentWait.until(ExpectedConditions.visibilityOf(element));
System.out.println("Element is visible: " + element.toString());
return true;
} catch (Exception e) {
System.out.println(
"Unable to locate the element: " + element.toString() + ", Exception: " + e.toString());
throw (e);
}
}
return false;
}
@anderson請找HTML代碼attatched – Gbru
@Andersson請找HTML代碼attatched – Gbru
可以讓我知道你有哪些進口例外。它應該是org.openqa.selenium.NoSuchElementException; –