1. Positioning elements: Baidu input box and search as an example
(1) ID locator: The id attribute is unique in an HTML document
The find_element_by_id () method locates elements through the id attribute
(2) Name locator
Find_element_by_name () method
(3) Class positioning
Find_element_by_class_name () method
(4) Tag positioning: tag is often used to define a class of functions, the probability of identifying an element through tag is very low
Find_element_by_tag_name () method
(5) Link positioning: Used to locate text links.
Find_element_by_link_txt ("News")
The Find_element_by_link_txt () method locates elements by using element tags for previous text information
(6) Partial link positioning: is a link positioning of a supplement, some text links longer, at this time need to take part of the text link positioning, only this part of the information can uniquely identify the link.
The Find_element_by_partial_link_text () method locates elements by partially textual information between the element label pairs
#coding =utf-8
From selenium import Webdriver
Driver = Webdriver. Firefox ()//Get Friefox Browser object, launch browser
Driver.get ("http://www.baidu.com";)//Enter URL into browser
driver.find_element_by_id ("kw"). Send_keys ("python")//Locate the Baidu input box and enter Python
driver.find_element_by_id ("su"). Click ()//position "Baidu button" to send a clicking event
#driver. Find_element_by_link_text ("News"). Click ()
#driver. Find_element_by_link_text ("hao123"). Click ()
driver.find_element_by_id ("kw"). Send_keys ("Python")
driver.find_element_by_id ("kw"). Clear ()
Driver.find_element_by_name ("WD"). Send_keys ("Python1")
‘‘‘
driver.find_element_by_id ("su"). Click ()
Driver.find_element_by_class_name ("S_ipt"). Send_keys ("Python")
Driver.find_element_by_class_name ("BG s_btn"). Click ()
Driver.find_element_by_tag_name ("Input"). Send_keys ("Python")
Driver.find_element_by_tag_name ("Input"). Click ()
Driver.quit ()//exit and close the browser and related drivers
‘‘‘
Python---positioning elements