Java 硒等待任何元素可见
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42944097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium Wait for anyone of Element to visible
提问by Vanjithkumar
While Clicking a particular button - my test site will open modal window.
单击特定按钮时 - 我的测试站点将打开模式窗口。
But the modal window opens are differ, either it opened with modal window 1 or modal window 2
但是打开的模态窗口是不同的,要么是用 modal window 1 or modal window 2
Both are having different title, different options and different locators.
Now I should have to wait until the modal window open Either 1 or 2
.
两者都有不同的标题、不同的选项和不同的定位器。现在我应该等到 modal window open Either 1 or 2
。
Is it possible to wait until either one modal window (WebElement) is visible?
是否可以等到任一模式窗口 (WebElement) 可见?
I have searched in WebDriverWait methods, but all methods are to wait until a particular WebElement to visible or clickable.
我在 WebDriverWait 方法中搜索过,但所有方法都是等到特定的 WebElement 可见或可点击。
I can't find a better method to wait until either one is visible.
我找不到更好的方法来等到任何一个可见。
Could you suggests any one method to solve this situation?
你能建议任何一种方法来解决这种情况吗?
采纳答案by Guy
You can use or
expected conditionsfor that
您可以使用or
预期条件为
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.or(
ExpectedConditions.visibilityOfElementLocated(By.id("id1")),
ExpectedConditions.visibilityOfElementLocated(By.id("id2"))
));
Or use cssSelector
or ,
或使用cssSelector
或,
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#id1, #id2"));