Selenium using XPath to locate the entire article

Source: Internet
Author: User
Tags xpath

One of the articles mentions XPath element positioning, but some of the articles do not fit into special and personalized scenarios. You can find the solution you need here in the text that provides the ultimate placement of XPath elements.

The first method:

Positioning by Absolute path (I'm sure you won't use this way)
By.xpath ("Html/body/div/form/input")

The second method:

By thinking that the other side is positioning
By.xpath ("//input")

The third method:

Positioning by Element Index
By.xpath ("//input[4]")

The fourth method:

Use XPath attribute positioning (combined with 2nd, 3rd method can be used)
By.xpath ("//input[@id = ' kw1 ']")
By.xpath ("//input[@type = ' name ' and @name = ' kw1 ']")

The Fifth method:

Use partial attribute value matching (the most powerful method)
By.xpath ("//input[start-with (@id, ' nice ')
By.xpath ("//input[ends-with (@id, ' very pretty")
By.xpath ("//input[contains (@id, ' so Beautiful ')]")

The 6th method:

Use an XPath axis (not used)

Selenium using XPath to locate the entire article

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.