html tool

2015年2月5日星期四

selenium动态等待 presence_of_element_located

动态等待页面元素加载:
add:http://selenium-python.readthedocs.org/en/latest/waits.html

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()
This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

[popexizhi]其中presence_of_element_located的首个参数应该都是大写要求吧?!
我修改的是是如下:WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, _xpath)))

没有评论:

发表评论