我有两个元素可以等待,我想要wait
直到它们中的任何一个出现在页面上。
我正在尝试使用xpath
定位器。但它不起作用。
By.xpath("//*[(contains(@id,'idNumber1')) or (contains(@id,'idNumber2'))]"));
这是可以实现的吗?
请帮帮我。
可以使用以下方式等待页面中的两个元素之一ExpectedConditions.or()
:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.or(
ExpectedConditions.elementToBeClickable(By.id("idNumber1")),
ExpectedConditions.elementToBeClickable(By.id("idNumber2"))
));
您还可以做一个OR
使用逗号的 CSS 选择器,
:
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#idNumber1, #idNumber2"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)