Selenium+python---xpath定位

 by  yoyo

 # coding:utf-8

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
# use xpath by id
driver.find_element_by_xpath("//*[@id='kw']").send_keys("python")
# use xpath by name
driver.find_element_by_xpath("//*[@name='wd']").send_keys("python")
# use xpath by class
driver.find_element_by_xpath("//*[@class='s_ipt']").send_keys("python")
# use xpath by other
driver.find_element_by_xpath("//*[@autocomplete='off']").send_keys("python")

# use xpath by input lable
driver.find_element_by_xpath("//input[@autocomplete='off']").send_keys("python")
driver.find_element_by_xpath("//input[@id='kw']").send_keys("python")
driver.find_element_by_xpath("//input[@name='wd']").send_keys("python")

# use 层级关系定位  by father
driver.find_element_by_xpath("//span[@id='s_kw_wrap']/input").send_keys("python")
driver.find_element_by_xpath("//form[@id='form']/span/input").send_keys("python")

 

posted @ 2019-04-02 18:11  山里姑娘  阅读(211)  评论(0编辑  收藏  举报