我这样做是这样的:
class AnyEc: """ Use with WebDriverWait to combine expected_conditions in an OR. """ def __init__(self, *args): self.ecs = args def __call__(self, driver): for fn in self.ecs: try: if fn(driver): return True except: pass
然后像这样…
from selenium.webdriver.support import expected_conditions as EC# ...WebDriverWait(driver, 10).until( AnyEc( EC.presence_of_element_located( (By.CSS_SELECTOR, "div.some_result")), EC.presence_of_element_located( (By.CSS_SELECTOR, "div.no_result")) ))
显然,同样实现一个
AllEc类也是微不足道的。
Nb。的
try:块为奇数。我很困惑,因为有些EC返回true /
false,而另一些EC会为False抛出异常。异常是由WebDriverWait捕获的,所以我的AnyEc事情产生了奇怪的结果,因为第一个抛出异常的事件意味着AnyEc没有继续进行下一个测试。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)