Using CSS selectors for element positioning in selenium

Source: Internet
Author: User
Tags xpath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.