我在python中使用selenium webdriver。
我想创建一个显式的等待弹出窗口出现。不幸的是,EC模块的常用方法不包括针对此问题的现成解决方案。在搜索其他许多帖子时,我发现我必须编写自己的ec条件.until(new ExpectedCondition() { * the condition and its return arguments *}
。
我很难找到有关正确编写此文档所使用的确切语法的文档。这里有一个Java示例:https://groups.google.com/forum/#!msg/selenium-users/iP174o0ddw4/l83n5C5rcPoJ。是否有人可以指向相关的文档(不是一般的等待,而是创建新的ec),或者如果我刚刚链接到的java代码只是帮助我编写python版本。
谢谢
最佳答案
如果您想等待任意条件,则根本不必使用ExpectedCondition
。您只需将函数传递给until
方法:
from selenium.webdriver.support.ui import WebDriverWait
def condition(driver):
ret = False
# ...
# Actual code to check condition goes here and should
# set `ret` to a truthy value if the condition is true
# ...
return ret
WebDriverWait(driver, 10).until(condition)
上面的代码将重复调用
condition
,直到以下任一项为真:condition
返回计算结果为true的值,已过去10秒(在这种情况下会引发异常)。