[Selenium] The most commonly used CSSSelector

CSSSelector

Example

Description

element.element

div.dropdown

Select all  <div> elements whose class=“dropdown”

element#element

div#new-input

Select all <div> elements whose id =“new-input”

element element

div p

Select all <p> elements who are under <div> element

element>element

div>p

Select all <p> elements whose father is <div> element

[attribute]

div[rowid]

Select all <div> elements who has attribute rowid

[attribute=value]

input[value=‘OK‘]

Select all <input> elements whose attribute value is ‘OK’

[attribute*=value]

a[src*=‘abc’]

Select all <a> elements whose attribute src contains  ‘abc’

:nth-child(n)

p:nth-child(2)

Select all <p> elements who is the second child of its  father

eg 1:  div.rtq-grid-row[rowid]  div.rtq-grid-cell:nth-child(5)  a

eg 2: div#fileUpDiv  input[value=‘OK‘]

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。