selenium之定位方法

2022-08-21 22:06:09 字數 1432 閱讀 4750

html元素定位的方法:

1、id     find_element_by_id

2、name      find_element_by_name

3、class      find_element_by_class_name

4、tag       find_element_by_tag_name

5、link       find_element_by_link_text

6、partial link         find_element_by_partial_link_text

xpath定位方法find_element_by_xpath

1、絕對路徑     find_element_by_xpath("/html/body/div/div[2]/div/form/span/input")    

2、元素屬性        find_element_by_xpath("//input[@id='kw']")   元素的屬性能夠唯一標識乙個元素

路徑不清楚的時候可以用*代替

3、層級和屬性結合               find_element_by_xpath("//span[@id='kw']/input") 

4、邏輯運算子,連線多個屬性需要用 and              find_element_by_xpath("//input[@id='kw' and @class='su']/span/input")   

css定位方法

1、class屬性用(.)來表示        find_element_by_css_selector(".s_pt")

2、id屬性用(#)來表示           find_element_by_css_selector("#su")

3、通過標籤名定位,不需要任何符號標識      find_element_by_css_selector("input")

(1)父子關係定位       find_element_by_css_selector("span>input")

(2)屬性定位               find_element_by_css_selector("[type='submit']")

(3)組合定位               上面幾種的組合("form.fm>span>input.s_ipt")

by定位元素(需要匯入by方法 from selenium webdriver.common.by import by)

find_element(by.id,'kw')

find_element(by.xpath,"//input[@id='kw']")

find_element(by.css_selector,"form.fm>span>input.s_ipt")

selenium之元素定位方法

4 class 5 link text 超連結文字 6 xpath 7 css定位 8 定位相同元素第二個 type text class s ipt name wd id kw maxlength 100 autocomplete off driver.find element by id kw ...

selenium定位方法

selenium定位方法 selenium定位元素的方法主要有18種 一 定位單個元素 1通過id find element by id 2通過name find element by name 3通過css find element by css selector 4通過xpath find el...

selenium元素定位方法

我們知道,webdriver api的呼叫以及自動化測試,務必從頁面元素的定位開始,那麼回顧之前的內容,webdriver提供了一系列的定位符以便使用元素定位方法。常見的定位符有以下幾種 idname class name taglink text partial link text xpath c...