id, name, class name, tag name,
link text, partial link text, xpath, css selector
下面主要介紹一下xpath:
一、xpath基本定位用法
1.1 使用id定位 -- driver.find_element_by_xpath('//input[@id="kw"]')
1.2 使用class定位 -- driver.find_element_by_xpath('//input[@class="s_ipt"]')
1.3 當然 通過常用的8種方式結合xpath均可以定位(name、tag_name、link_text、partial_link_text)以上只列舉了2種常用方式哦。
二、xpath相對路徑/絕對路徑定位
2.1 相對定位 -- 以// 開頭 如://form//input[@name="phone"]
2.2 絕對定位 -- 以/ 開頭,但是要從根目錄開始,比較繁瑣,一般不建議使用 如:/html/body/div/a
三、xpath文本、模糊、邏輯定位
3.1【文本定位】使用text()元素的text內容 如://button[text()="登錄"]
3.2 【模糊定位】使用contains() 包含函數 如://button[contains(text(),"登錄")]、//button[contains(@class,"btn")] 除了contains不是=等於
3.3 【模糊定位】使用starts-with -- 匹配以xx開頭的屬性值;ends-with -- 匹配以xx結尾的屬性值 如://button[starts-with(@class,"btn")]、//input[ends-with(@class,"-special")]
3.4 使用邏輯運算符 -- and、or;如://input[@name="phone" and @datatype="m"]
四、xpath軸定位
4.1 軸運算
parent:父節點
preceding-sibling:當前元素節點標簽之前的所有兄弟節點
preceding:當前元素節點標簽之前的所有節點

注意:
#定位 找到元素 -- 做到唯一識別
#優先使用id
#舍棄:有下標的出現、有絕對定位的出現、id動態變化時舍棄
其它文章:https://www.cnblogs.com/hanmk/p/8997786.html
https://www.cnblogs.com/hanmk/p/9015502.html