如何使Selenium WebDriver等待到组合的预期条件?
基本上,Java的类似问题是
asked
和
answered
,但这种方法
OR
(
docs
)这里不是用于Python绑定的(
expected_conditions.py
在GitHub上)
我有一个非常缓慢的回调,结果是:
-
身份证号码=
_report_success
如果所有东西都正确加载
-
身份证号码=
_report_error
万一发生故障
所以,我要等到
_报告成功
或
_报告错误
变得清晰可见。
另外,这些条件非常简单:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, '_report_success')))
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, '_report_error')))
在Java中,组合版本如下所示:
driverWait.until(ExpectedConditions.or(
ExpectedConditions.presenceOfElementLocated(...),
ExpectedConditions.presenceOfElementLocated(...)
));
当然,我可以做一个循环并用间隔来检查两者的存在(实际上就像在WebDrReValue.to中实现的那样),但是我正在寻找更优雅和灵活的解决方案。毕竟,如果这种需求的方法出现在Java版本中,为什么它不在Python绑定中?