定位元素:8种元素定位方式
1. id
2. name
3. class name
4. tag name
5. link text
6. partial link text
7. xpath
8. css selector
from selenium import webdriver
driver = webdriver.Chrome()
#driver = webdriver.Firefox()
#driver = webdriver.Ie()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("python")
driver.find_element_by_name("wd").send_keys("python1")
driver.find_element_by_class_name("s_ipt").send_keys("python2") #一般不唯一,不建议使用
driver.find_element_by_tag_name("input").send_keys("python3") #一般不唯一,不建议使用
driver.find_element_by_link_text("地图").click()
driver.find_element_by_partial_link_text("地").click()
driver.find_element_by_xpath(".//*[@id='kw']").send_keys("python4") #需掌握
driver.find_element_by_css_selector("#kw").send_keys("python5") #需掌握