Web Automation 3-selenium Basic Operations Css/xpath

Source: Internet
Author: User
Tags tag name xpath

1.xptah can be positioned by the attributes of the element's ID, name, class

Driver.find_element_by_xpath ("//input[@id = ' kw1 ']")

Driver.find_element_by_xpath ("//*[@name = ' wd ']")

Driver. Find_element_by_xpath ("//*[@class = ' s_ipt ']")

2. If an element ID, name, and class attribute are not available, you can also navigate to the

Driver.find_element_by_xpath ("//*[@autocomplete = ' off ']")

Driver.find_element_by_xpath("//input[@type = ' text ']")

3. Logical operation

4.xpath Index

Driver.find_element_by_xpath ("//div[@id = ' sidebar ']/ul/li[3]/a"). Click ()

Driver.find_element_by_xpath ("//div[@id = ' sidebar ']/ul/li[3]/ul[1]/li[2]"). Click ()

Css

1.css: Attribute Positioning

The following is the HTML code of the Baidu input box:

<input id= "kw" class= "S_ipt" type= "text" autocomplete= "Off" maxlength= "+" name= "wd"/>

The CSS uses the # number to denote the id attribute, such as: #kw

CSS uses. Represents the class attribute, such as:. S_ipt

CSS directly with the tag name, without any identifiers, such as: input

2.css: Other properties

CSS can be located in addition to the three general properties of tags, class, id, or other properties.

Here are the formats for locating other properties

Summary: XPath is more powerful, geographically local, but slower

CSS is more concise, processing speed is fast, but some features limited positioning

Web Automation 3-selenium Basic Operations Css/xpath

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.