from selenium.webdriver.common.by import By import time from selenium import webdriver from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait class BasePage(object): def __init__(self, driver): self.driver: webdriver.Chrome = driver def find_id(self, id): ele: WebElement = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, id))) time.sleep(0.5) return ele def find_xpath(self, xpath): ele: WebElement = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, xpath))) time.sleep(0.5) return ele def find_text(self, text): ele: WebElement = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.XPATH, "//*[text()= "'"{0}"'"]".format(text))))
封装常用的webdriver方法
最新推荐文章于 2022-07-01 13:06:29 发布
这个博客介绍了如何使用selenium库封装一些常用的webdriver操作,包括根据ID、XPath、文本和placeholder查找元素,以及获取表格单元格数据和睡眠功能。
摘要由CSDN通过智能技术生成