我如何编写Selenium函数来等待Python中只有类标识符的表?我在学习使用Selenium的Python Webdriver函数时遇到了恶魔。
从seleniumhq文档PDF:
import contextlib import selenium.webdriver as webdriver import selenium.webdriver.support.ui as ui with contextlib.closing(webdriver.Firefox()) as driver: driver.get('http://www.google.com') wait = ui.WebDriverWait(driver,10) # Do not call `implicitly_wait` if using `WebDriverWait`. # It magnifies the timeout. # driver.implicitly_wait(10) inputElement=driver.find_element_by_name('q') inputElement.send_keys('Cheese!') inputElement.submit() print(driver.title) wait.until(lambda driver: driver.title.lower().startswith('cheese!')) print(driver.title) # This raises # selenium.common.exceptions.TimeoutException: Message: None # after 10 seconds wait.until(lambda driver: driver.find_element_by_id('someId')) print(driver.title)