通過 css_selector 定位元素

來源:互聯網
上載者:User

標籤:css_selector   定位元素

常用符號數位:
# 表示id
. 表示class
> 表示子項目,層級
一個空格也表示一個子項目,但是所有的子項目相當於xpath中的相對路徑,舉個例子driver.find_element_by_xpath(‘//div//inptut‘),可以寫成driver.find_element_by_css_selector(‘div input‘)

常用方法舉列:
#input 選擇id為input的節點
.Volvo 選擇class為Volvo的節點
div#radio>input 選擇id為radio的div下的所有的input節點
div#radio input 選擇id為radio的div下的所有的子孫後代input節點
div#radio>input:nth-of-type(4) 選擇id為radio的div下的第4個input節點
div#radio>nth-child(1) 選擇id為radio的div下的第1個子節點
div#radio>input:nth-of-type(4)+label 選擇id為radio的div下的第4個input節點之後挨著的label節點
div#radio>input:nth-of-type(4)~labe 選擇id為radio的div下的第4個input節點之後的所有label節點
input.Vovlo[name=‘identity‘] 選擇class為.Volvo並且name為identity的input節點
input[name=‘identity‘][type=‘radio‘]:nth-of-type(1) 選擇name為identity且type為radio的第1個input節點
input[name^=‘ident‘] 選擇以ident開頭的name屬性的所有input節點
input[name$=‘entity‘] 選擇以‘entity‘結尾的name屬性的所有input節點
input[name*=‘enti‘] 選擇包含‘enti‘的name屬性的所有input節點
div#radio>*.not(input) 選擇id為radio的div的子節點中不為input的所有子節點
input:not([type=‘radio‘]) 選擇input節點中type不為radio的所有節點
input:contains("OK") 選擇input的值是OK的節點


通過 css_selector 定位元素

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.