wait.until(ExpectedConditions.visibilityOf Element1 OR Element2) [英] wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)
问题描述
我想使用带有TWO元素的 wait.until(ExpectedConditions)
。
我正在运行测试,我需要 WebDriver
等待 Element1或Element2 中的任何一个出现。然后我需要选择先出现的人。我试过了:
I want use wait.until(ExpectedConditions)
with TWO elements.
I am running a test, and I need WebDriver
to wait until either of Element1 OR Element2 shows up. Then I need to pick whoever shows up first. I've tried:
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@class='....']"))) || wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[@class='... ']")));
// Then I would need:
String result = driver.findElement(By.xpath("...")).getText() || driver.findElement(By.xpath("...")).getText();
总之,我需要等到两个元素中的任何一个出现。然后挑选出现的人(他们不能同时出现)
请帮助。
To sum up, I need to wait until either of the TWO elements shows up. Then pick whoever shows up (they cannot show up simultaneously) Please Help.
推荐答案
不幸的是,没有这样的一个命令。您可以通过尝试和捕获来克服这个问题,或者我建议您使用 Watij 。
Unfortunately, there is no such a command. You can overcome this by try and catch, or I would better recommend you to use Watij.
这篇关于wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!