定位元素的一种用法
from selenium.webdriver.common.by import By
driver.find_element("id", "kw")
driver.find_element("xpath", "xxx")
driver.find_element("link text", "xxx")
driver.find_element("partial link text", "xxx")
driver.find_element("name", "xxx")
driver.find_element("tag name", "xxx")
driver.find_element("class name", "xxx")
driver.find_element("css selector", "xxx")
def is_exist(self,locator,timeout=30,frequency=0.5):
"""
locator 参数是定位方式,如("id", "kw"),把两个参数合并为一个
*号是把两个参数分开传值
使用方法:
locator = ("id", "kw")
driver.find_element(*locator)
class BasePage: """页面基类""" def __init__(self,driver): #构造函数 self.driver = driver
def openpage(self,url): """ 打开页面""" self.driver.get(url) self.driver.implicitly_wait(10) #隐式等待默认时间 self.driver.maximize_window() #最大化窗口
def getelement(self,*locator): """获取页面元素""" return self.driver.find_element(*locator)
def getelements(self,*locator): """获取页面元素集""" return self.driver.find_elements(*locator)
------------------------------------------------------------------------------------------------------------------------