element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("someId")) is_disappeared = WebDriverWait(driver, 30).until_not(lambda x: x.find_element_by_id("someId").is_displayed())
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
class Demo():
def __init__(self,*locator):
self.driver = webdriver.Chrome()
self.locator = locator
def func_name(self,param): # param 参数,用来接收driver
return param.find_elements(*self.locator)
def find(self):
return WebDriverWait(self.driver, 10).until(self.func_name) # until(函数名),用匿名函数,比较方便传递定位信息 *locator
def ele(self):
self.driver.get("http://www.baidu.com")
ele = self.find()
print(ele)
if __name__ == '__main__':
Demo('xpath','//span[@class="title-content-title"]').ele()
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
def func(param):
return param.find_elements("xpath",'//span[@class="title-content-title"]')
def find(driver):
return WebDriverWait(driver, 10).until(func)
def baidu():
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
ele = find(driver)
print(ele)
baidu()