我使用此代码来检查隐形:等待多个元素,成为无形的硒的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