如何使用 selenium xpath 等待页面中的两个元素之一 [英] How to wait for either of the two elements in the page using selenium xpath
本文介绍了如何使用 selenium xpath 等待页面中的两个元素之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个元素可以等待,我想等待
直到它们中的任何一个出现在页面上.
I have two elements I can wait for, I want to wait
until either of them appears on the page.
我正在尝试使用 xpath
定位器.但它不起作用.
I am trying to use xpath
locator. But it is not working.
By.xpath("//*[(contains(@id,'idNumber1')) or (contains(@id,'idNumber2'))]"));
这能实现吗?
请帮帮我.
Is this achievable?
Please help me out.
推荐答案
可以使用 ExpectedConditions.or()
等待页面中的两个元素之一:
It is possible to wait for one of two elements in the page using ExpectedConditions.or()
:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.or(
ExpectedConditions.elementToBeClickable(By.id("idNumber1")),
ExpectedConditions.elementToBeClickable(By.id("idNumber2"))
));
您还可以使用逗号 ,
对 CSS 选择器执行 OR
:
You can also do an OR
with a CSS selector using a comma ,
:
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#idNumber1, #idNumber2"));
这篇关于如何使用 selenium xpath 等待页面中的两个元素之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文