Selenium positioning using Xpath

Source: Internet
Author: User

One article mentions xpath element locating, but some of the articles cannot adapt to special and personalized scenarios. In this article, we provide the ultimate article on the positioning of xpath elements. You can find the solutions you need here.

Method 1: positioning through absolute paths (I believe you will not use this method)

By. xpath ("html/body/div/form/input ")

Method 2: locate through relative paths (the most commonly used method)

By. xpath ("// input ")
Method 3: locate by element index

By. xpath ("// input [4]")
Method 4: Use the xpath attribute to locate (which can be used in combination with the methods in 2nd and 3rd)

By. xpath ("// input [@ id = 'kw1']")

By. xpath ("// input [@ type = 'name' and @ name = 'kw1']")
Method 5: use partial property value matching (the most powerful method)

By. xpath ("// input [start-with (@ id, 'Nice ')
By. xpath ("// input [ends-with (@ id, 'Beautiful ')
By. xpath ("// input [contains (@ id, 'So Beautiful ')]")
6th methods: Use the xpath axis (not used)

I hope these methods will help you.

Selenium positioning using Xpath

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.