1
我有一个名为webdriver.py
的文件,它实现了selenium.webdriver
库中的方法。有同时处理最多的,我需要的情况下,等待功能:Python,Selenium - 处理多个等待条件
def wait_for(self, func, target=None, timeout=None, **kwargs):
timeout = timeout or self.timeout
try:
return WebDriverWait(self, timeout).until(func)
except TimeoutException:
if not target:
raise WebDriverException('Wait for: "%s" failed!' % inspect.getsource(func).strip())
raise NoSuchElementException(target)
凡func
是一个选择。
的问题是,有时DOM元素将是不可见的,从而引起异常,并检测失败。所以我想延长wait_for
也等待元素变得可见。
喜欢的东西
def wait_for(self, func, target=None, timeout=None, **kwargs):
timeout = timeout or self.timeout
try:
return WebDriverWait(self, timeout).until(EC.element_to_be_clickable(func)).until(func)
except TimeoutException:
if not target:
raise WebDriverException('Wait for: "%s" failed!' % inspect.getsource(func).strip())
raise NoSuchElementException(target)
EC
是selenium.driver.expected_conditions
这当然不是工作 - 不支持任何until().until()
语法..什么事情发生,就像EC
不存在。
任何想法?
感谢您的帮助,我还使用“从selenium.webdriver.support导入expected_conditions作为EC”来解决EC问题。 – Oleg
我也认为它应该是:“By.ByCssSelector”根据https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.ByCssSelector.html – Oleg
@ h3d0它应该是''By.CSS_SELECTOR为Python检查http://selenium-python.readthedocs.org/api.html?highlight=by.css_selector#selenium.webdriver.common.by.By.CSS_SELECTOR –