Sizzle CSS3 also provides some pseudo-classes that directly select form elements
:input
: Finds All input elements (includes Textareas, selects, and buttons).
:text
,,,,,,, :checkbox
:file
:password
:submit
:image
:reset
, :button
: Finds the INPUT element with the specified input type (: Button also fin DS button elements).
Here are some synonyms for XPath and CSS locator comparison
Positioning method |
Xpath |
Css |
Label |
Div |
Div |
by ID |
div[@id = ' Eleid ') |
Div#eleid |
by class |
div[@class = ' Eleclass ') Div[contains (@class, ' Eleclass ')] |
Div.eleclass |
By property |
div[@title = ' Move mouse here '] |
Div[title=move Mouse here] Div[title^=move] Div[title$=here] Div[title*=mouse] |
Positioning child elements |
div[@id = ' Eleid ']/* Div/h1 |
Div#eleid >* Div#eleid >H1 |
locating descendant elements |
div[@id = ' Eleid ']//h1 |
Div H1 |
by index |
LI[6] |
Li:nth (5) |
by content |
A[contains (., ' Issue 1164 ')] |
A:contains (Issue 1164) |
Position parent elements retroactively based on child elements |
Li[a[contains (., ' Issue 1244 ')] *[./a[contains (., ' Issue 1244 ')] Ul[.//a[contains (., ' Issue 1244 ')] |
Li{a:contains (Issue 1244)} Ul{a:contains (Issue 1244)} |
Positioning based on neighboring elements |
Li[preceding-sibling::li[contains (., ' Issue 1244 ')] Ul[preceding-sibling::ul[.//a[contains (., ' Issue 1244 ')] |
Css=li:contains (Issue 1244) + Li Css=ul{a:contains (Issue 1244)} ~ UL |
Using CSS selectors for element positioning in selenium