八大元素定位代码

ID定位:
driver.find_element(By.ID, "kw").send_keys("lol")

Name定位:
driver.find_element(By.NAME, "wd").send_keys("lol")

单机某个链接LINK_TEXT:
driver.find_element(By.LINK_TEXT, "hao123").click()

关键字搜索且该页面没有重复的字PARTIAL_LINK_TEXT:
driver.find_element(By.PARTIAL_LINK_TEXT, "hao").click()

xpath定位:

绝对路径:/ 开头是绝对路径
/html/body/div[1]/div[1]/div[5]/div/div/form/span[1]/input
相对路径:// 开头是相对路径
//input
1.相对路径+索引定位:
//from/span[1]/input

2.相对路径+属性定位:
//input[@autocomplete='off']

3.相对路径+通配符定位:
//[@autocomplete='off']
//
[@*='off']
复制xpath经常会出错,不是万能的

4.相对路径+部分属性值定位:
以开头://[starts-with(@autocomplete,'of')]
一结尾://
[substring(@autocomplete,2)='ff']
包含://*[contains(@autocomplete,'of')]

原文地址:https://www.cnblogs.com/Sorry-/p/14813194.html