我想将 wait.until(ExpectedConditions)
与两个元素一起使用。我正在运行测试,我需要 WebDriver
等待 Element1 或 Element2 出现。然后我需要选择先出现的人。我试过了:
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();
总而言之,我需要等到两个元素中的任何一个出现。然后选择出现的人(他们不能同时出现)请帮忙。
原文由 user2058100 发布,翻译遵循 CC BY-SA 4.0 许可协议
不幸的是,没有这样的命令。你可以通过 try and catch 来克服这个问题,或者我会更好地推荐你使用开源 Ruby 库 Watir 。