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