There are seven ways to locate elements in selenium:
1. Identifier positioning
This is the most common way of positioning, the default is identifier in selenium, in this strategy, the first page element using ID will be recognized, if the element with the specified ID is not used, then the first name will be identified with the specified criteria to match the element. For example: the Identifier=continue//positioning page element is Continue because identifier positioning is the default way, so "identifier=" can not be written.
2. ID positioning (most commonly used)
This positioning method is narrower than the identifier positioning range and, of course, more specific , if you know the element ID feature, use this method, for example: id=loginfrom//positioning the page element from
3. Name Locator
The name locator will recognize the first UI element that matches the name attribute. If multiple elements have the same name attribute, you can use filters to further refine your targeting strategy. The default filter is value (matches the value feature):
Example: name=continue value=clear//Position page element is Continue, value is Clear
Tips:
The above three positioning is selenium can be tested without relying on the position of the UI element on the page. So, when the page structure changes, the test can still pass. Sometimes it is important for designers to change pages frequently, by locating elements through the ID and name features.
4. XPath positioning (common)
XPath is a language that locates elements in an XML document. Because HTML can be seen as an implementation of XML, selenium users
However, this powerful language is used to locate elements in Web applications.
For example: xpath=/html/body/form[1]//absolute path (any slight change in HTML will cause a failure)
5. Positioning via hyperlinks
You can locate the hyperlink by connecting the text, and if the two linked text is the same, the first match will be recognized. Cases
Example: link=continue//Positioning page element connection text is continue
6. Dom Positioning
The document Object model is used to describe HTML documents that can be accessed using JavaScript.
Example: Dom=document.getelementbyid (' loginform ')//position page element form
7.CSS positioning
CSS (cascading stylesheets) is a language that is used to describe the performance of HTML and XML documents. CSS uses selectors to
The page element binding property. These selectors can be used by selenium as a different positioning strategy. Example: Css=form#loginform
Positioning page Elements Form
This article from the "Eight arm to test" blog, declined reprint!
Selenium (i) method for locating elements