方法一:元素ID定位
username = driver.find_element(By.ID,"username")
方法二:元素class定位
login = driver.find_element(By.CLASS_NAME,"login")
方法三:元素name定位
password = driver.find_element(By.NAME,"password")
方法四:元素tag定位
p = driver.find_element(By.TAG,"p")
方法五:超链接文本(精确匹配)定位
atext = driver.find_element(By.LINK_TEXT,"抗击肺炎")
方法六:超链接文本(模糊匹配)定位
atext = driver.find_element(By.PARTIAL_LINK_TEXT,"肺炎")
方法七:通过XPATH定位
lis = driver.find_element(By.XPATH,"/html/body/div/ul[2]/li[1]")
方法八:通过CSS定位
lis = driver.find_element(By.CSS_SELETOR,"body>div>ulli:nth-child(2)")
标签:定位,python,selenium,元素,driver,element,pytest,方法,find
From: https://www.cnblogs.com/oytao/p/17649546.html