selenium webdriver find_element_by_****元素定位


 

定位方式:

firefox元素定位,直接使用F12調用

CSS常用語法

<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
<a href="http://news.baidu.com" name="tj_trnews" class="mnav">新聞</a>
<div class="bdbriimgtitle">更多產品</div>

find_element_by_id("kw")
find_element_by_link_text('新聞')
find_element_by_partial_link_text("產品")
find_element_by_xpath('//*[@id="kw"]')
find_element_by_xpath('//*[@class="s_ipt"]')
find_element_by_xpath('//*input[@maxlength="255"]')
find_element_by_xpath('//*[@id="kw"]')
find_element_by_xpath("//span[@class='bg']/input") 往上級找,依次為爸爸、我
find_element_by_xpath("//form[@id='form']/span[@class='bg']/input") 往上級找,依次為爺爺、爸爸、我
find_element_by_xpath("//*[@id='kw' and @name='wd']") 使用條件組合
#css
find_element_by_css_selector("#kw") #號表示id
find_element_by_css_selector("[name=kw]") #號表示id
find_element_by_css_selector(".s_ipt") .表示class屬性
find_element_by_css_selector("span.bg > input#kw") 父親叫span,類為bg,我是input,id是kw,即往上找


xpath的另一種方式:
/html/body/div[1]/div[5]/div[1]/div[3]/div[1]/div[1]/div[2]/div[3]/a

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM