Selenium has 6 methods to locate the control (locating elements ):
1. The control is hyperlink: locate the string as the keyword "link =" and add the link text, as shown below:
Selenium. Select ("link = register here ");
2. The control has the name or ID attribute. If the name or ID attribute can be distinguished, you can use either of the following three types of positioning strings:
/* Control with name or ID property that can identify itself. locator string format for Name property is: "identifier = namepropertyvalue" or "name = namepropertyvalue" or "namepropertyvalue"; for ID property is: "identifier = idpropertyvalue ", or "id = idpropertyvalue" or "idproperty" */<br/> selenium. select ("identifier = password"); <br/> // or <br/> selenium. select ("name = password"); <br/> // or <br/> selenium. select ("password ");
If the name or ID attribute cannot uniquely identify the control, you need to add other attributes for filtering:
/* If name or ID property cannot identify a control, we need to add other property to filter it. the locator Format String is: "[name =] namepropertyvalue [otherproprety1 =] otherpropertyvalue1 [otherproperty2 =] otherpropertyvalue2 ". */<br/> // also add value property <br/> selenium. select ("name = triptype value = oneway") <br/> // or <br/> selenium. select ("triptype oneway ")
3. No name or ID attribute. Use XPath to locate the attribute;
XPath can be divided into absolute paths and relative paths. We recommend that you use relative paths. However, you can use absolute paths to check the structure and position of the control on the page.
4. the DOM method is used. In fact, the control has the name or ID attribute, or the XPath locator string format method;
5. CSS
6. Traverse what you need from a type of control based on a specific Identifier;
Selenium uses identifier by default for positioning strings that are not defined by the selenium keyword. Selenium uses the XPath method by default; selenium uses DOM by default for positioning strings starting with the document keyword.