显示等待WebDriverWait+lambda
代码,关键代码标红
参考文章:https://www.cnblogs.com/yoyoketang/p/6517477.html
#coding:utf-8 ''' 这里写了一个百度搜索页的pageobject ''' from PageElement.readYaml import parseyaml from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC class Baidu_page(): ''' 百度搜索page类 ''' getElement = parseyaml() search_box = getElement["baiduPage"]["search_box"]["value"] baidu_button = getElement["baiduPage"]["baidu_button"]["value"] search_result = getElement["baiduPage"]["search_result"]["value"] def __init__(self,driver): self.driver = driver def input_search(self,keyword,type_a="css"): '''输入搜索关键词''' self.driver.find_element(type_a,self.search_box).send_keys(keyword) def click_baidubutton(self,type_a="css"): '''点击百度一下按钮''' self.driver.find_element(type_a, self.baidu_button).click() def verification_result(self,type_a="css"): '''用例结果验证''' WebDriverWait(self.driver,10).until(lambda x: x.find_element("css selector",self.search_result)) results = self.driver.find_elements("css selector",self.search_result) nanjing_baike = results[0].text return nanjing_baike