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