XPath positioning Daquan

Source: Internet
Author: User

  

Selenium using XPath to locate the entire article 

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 approach: positioning with absolute paths (I'm sure you won't use this way)

By.xpath ("Html/body/div/form/input")
By.xpath ("//input")
Third method: Positioning by Element Index
By.xpath ("//input[4]")
Fourth method: Use the XPath attribute to locate (combined with the 2nd, 3rd method can be used)
By.xpath ("//input[@id = ' kw1 ']") 
By.xpath ("//input[@name = ' kw1 ']") 
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 ')]")
6th method: Using the XPath axis (not used)

Hopefully, these methods will help you.

XPath positioning Daquan

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.