from selenium import webdriver
driver = webdriver.Chrome()
#前提,在当前页面当中,不管用哪种定位方式,一定要是唯一的
#八种定位方式:#id、#name、#class_name、#input3(tag_name、link_text、partial_link_text)、#xpath、css
#id
driver.find_element_by_id("kw")
driver.find_element_by_css_selector("#kw") # 井号表示ID
#name
driver.find_element_by_name("wd")
driver.find_element_by_css_selector("input[@name='wd']") #xpath
driver.find_element_by_css_selector("input[name='wd']") #css
#class
driver.find_element_by_class_name("s_ipt")
driver.find_element_by_css_selector("input[@name='s_ipt']")#xpath
driver.find_element_by_css_selector(".s_ipt") #css
#input3种
driver.find_element_by_tag_name("text")
driver.find_element_by_link_text("新闻")
driver.find_element_by_partial_link_text("闻")
#xpath 和 css
#绝对路径
driver.find_elements_by_xpath("/html/body/div/div/div/div/form/span/iput")
driver.find_elements_by_xpath("/html/body/div/div/div/div/form/span[1]/input[6]")
#id
driver.find_element_by_xpath("//*[@id='kw']")
driver.find_element_by_xpath("//input[@id='kw']")
driver.find_element_by_css_selector("#kw") # 井号表示ID
driver.find_element_by_css_selector("input[name='wd']") #css
driver.find_element_by_css_selector(".s_ipt") #css
#name
driver.find_element_by_xpath("//input[@name='wd']")
driver.find_element_by_xpath("//span[@class=]")
"""
<input id="kw" name="wd"/>
<input id="kw" name="bb"/>
<input aa="aa" name="wd"/>
"""
driver.find_element_by_xpath("//[@id='kw' and @name='wd']")
#CSS用法
driver.find_element_by_css_selector("html > body> div> div> div> div> form> span[1]/input[6]")
driver.find_element_by_css_selector("#kw") # 井号表示ID
driver.find_element_by_css_selector("input[name='wd']") #css
driver.find_element_by_css_selector(".s_ipt") #css