Element positioning of selenium automation test

Source: Internet
Author: User

Element positioning of selenium automation test

First, selenium positioning method

The key to automated testing is to accurately manipulate the test object, so you need to accurately locate the page elements of the system under test, there are several positioning methods:

By.classnme (String className)

By.cssselector (String selector)

By.id (String ID)

By.linktext (String linkText)

By.name (String name)

By.partiallinktext (String linkText)

By.tagname (String name)

By.xpath (String XPath)

Ii. Introduction of XPath methods

1, the positioning element using the most or XPath method, you can use the Firepath plugin in Firefox to get the value of XPath;

2, xpaht commonly used symbols Description:

/represents absolute path, absolute path starts from root directory

Represents a relative path

. Represents the previous layer

.. Represents a previous layer

* indicates a wildcard character

@ denotes property

[] Represents a judgment expression

Iii. Introduction to the use of XPath

1. Open the Firefox browser that installs the Firepath plugin

2. Open Baidu Homepage

3. Right-click on the Search bar to select inspect in Firepath

4. Display the value of XPath in Firepath

 

With the Firepath tool, we can quickly locate elements, but sometimes the expression or the way we navigate to an element is not what we want, so we need to modify it manually based on the XPath positioning rules.

Iv. code Examples

Open the browser to enter Baidu, maximize the window, enter search content, click Baidu a bit;

Element positioning of selenium automation test

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.