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 –