Selenium study Note 3

Source: Internet
Author: User

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.

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.