我使用此代碼來檢查隱形:等待多個元素,成爲無形的硒的Java
WebDriverWait wait = new WebDriverWait(driver,40);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(<some xpath>)));
這完美的作品如果只有一個對應於網頁中的XPath元素。
我有在我試圖寫一個腳本的網頁,我需要的硒等待所有三個。
注意:我沒有使用絕對xpath。
我使用此代碼來檢查隱形:等待多個元素,成爲無形的硒的Java
WebDriverWait wait = new WebDriverWait(driver,40);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(<some xpath>)));
這完美的作品如果只有一個對應於網頁中的XPath元素。
我有在我試圖寫一個腳本的網頁,我需要的硒等待所有三個。
注意:我沒有使用絕對xpath。
ExpectedConditions.invisibilityOfElementLocated
檢查第一個元素。在你的情況下,你可以編寫自己的ExpectedCondition
的實現,你必須檢查是否爲每個找到的元素顯示對象。
爲例(未測試):
private static void waitTillAllVisible(WebDriverWait wait, By locator) {
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Iterator<WebElement> eleIterator = driver.findElements(locator).iterator();
while (eleIterator.hasNext()) {
boolean displayed = false;
try {
displayed = eleIterator.next().isDisplayed();
}
catch (NoSuchElementException | StaleElementReferenceException e) {
// 'No such element' or 'Stale' means element is not available on the page
displayed = false;
}
if (displayed) {
// return false even if one of them is displayed.
return false;
}
}
// this means all are not displayed/invisible
return true;
}
});
}
你有3 webelement具有相同的XPath? – NarendraR
是的,這個問題沒有清楚嗎? – XChikuX