五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

Python腳本Selenium及頁面Web元素定位詳解

發(fā)布日期:2021-12-21 18:24 | 文章來源:源碼之家

Selenium特點

開源,免費

多瀏覽器支持:firefox、chrome、IE

多平臺支持:linux 、windows、MAC

多語言支持:java、python、ruby、php、C#、

對web頁面有良好的支持

簡單(API 簡單)、靈活(用開發(fā)語言驅(qū)動)

支持分布式測試用例執(zhí)行一、

八種定位方式

1、driver.find_element_by_xpath(value)

可以使用自帶的copy xpath 進行定位
不推薦使用這種方法進行元素定位,后續(xù)開發(fā)修改代碼路徑發(fā)生變化就需要重新進行定位

// 使用xpath進行定位
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//通過id定位到輸入框的位置,send_keys('') 往輸入框填寫內(nèi)容
driver.find_element_by_name("wd").send_keys("Selenium八大元素定位")
//通過id定位到按鈕的位置并進行點擊,click() 點擊操作
driver.find_element_by_id("su").click()
//通過xpath定位獲取元素位置
driver.find_element_by_xpath('//*[@id="2"]/h3/a').click()
 

利用元素屬性進行xpath定位

// 利用元素屬性進行xpath定位
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//通過id定位到輸入框的位置,send_keys('') 往輸入框填寫內(nèi)容
driver.find_element_by_name("wd").send_keys("Selenium八大元素定位")
//通過id定位到按鈕的位置并進行點擊,click() 點擊操作
driver.find_element_by_id("su").click()
//通過元素屬性進行xpath定位  元素的值需要是唯一的
driver.find_element_by_xpath('//a[@ rel="external nofollow" ]').click()
 

2、driver.find_element_by_css_selector(value)

// 搜索百度使用f12定位到輸入框的位置
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
 
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//標簽名及屬性(含屬性值)組合定位,方式有很多不一一舉例
driver.find_element_by_css_selector('input[name="wd"]').send_keys("Selenium八大元素定位")
 

3、driver.find_element_by_id(value)

// 搜索百度使用f12定位到按鈕的位置
<input type="submit" id="su" value="百度一下" class="bg s_btn">
// 使用id 定位到輸入框的位置
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//通過id定位到按鈕的位置并進行點擊,click() 點擊操作
driver.find_element_by_id("su").click()

4、driver.find_element_by_name(value)

// 搜索百度使用f12定位到輸入框的位置
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
 
// 使用name 定位到輸入框的位置
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//通過id定位到輸入框的位置,send_keys('') 往輸入框填寫內(nèi)容
driver.find_element_by_name("wd").send_keys("Selenium八大元素定位")
 

5、driver.find_element_by_class_name(value)

// 搜索百度使用f12定位到輸入框的位置
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
 
// 使用name 定位到輸入框的位置
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
driver.find_element_by_class_name("s_ipt").send_keys("Selenium八大元素定位")
 

6、driver.find_element_by_tag_name(value)

// 使用標簽名進行定位
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
driver.find_element_by_tag_name("input")//通過標簽名去定位,不推薦重復率很高
 

7、driver.find_element_by_link_text(value)

// 搜索百度使用f12定位到按鈕的位置
<a  rel="external nofollow"  rel="external nofollow"  target="_blank" class="mnav c-font-normal c-color-t">新聞</a>
 
//此定位方式主要是對超鏈接進行定位,填寫的內(nèi)容是完整的超鏈接文字
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//此定位方式主要是對超鏈接進行定位,也就是html中的<a>標簽,括號中填寫的值是完整的超鏈接文字
driver.find_element_by_link_text("新聞").click()
 

8、driver.find_element_by_partial_link_text(value)

// 搜索百度使用f12定位到按鈕的位置
<a  rel="external nofollow"  rel="external nofollow"  target="_blank" class="mnav c-font-normal c-color-t">新聞</a>
 
//此定位方式主要是對超鏈接進行定位,填寫的內(nèi)容是部分的超鏈接文字
from selenium import webdriver
driver = webdriver.Chrome() //打開谷歌
driver.get("http://www.baidu.com") //打開百度鏈接
//此定位方式主要是對超鏈接進行定位,也就是html中的<a>標簽,括號中填寫的值是部分的超鏈接文字
driver.find_element_by_partial_link_text("新").click()
 

以上就是Python腳本Selenium及頁面Web元素定位詳解的詳細內(nèi)容,更多關(guān)于腳本Selenium頁面Web元素定位的資料請關(guān)注本站其它相關(guān)文章!

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部