Xpath定位练习

来源:互联网 发布:算法帝国 编辑:程序博客网 时间:2024/06/04 19:42

#!/usr/bin/env
#coding=utf-8
from selenium import webdriver
import time

driver=webdriver.Firefox()
driver.get('http://www.baidu.com')
#driver.find_element_by_xpath("//input[@id='kw']").send_keys("selenium")
#driver.find_element_by_xpath("//div[@id='head']/div/div/div/form/span/input").send_keys("selenium")
driver.find_element_by_xpath("//div[@class='s_form_wrapper']/form/span/input").send_keys("selenium")
#driver.find_element_by_xpath("/html/body/div[3]/div[2]/div/div/div/form/span/input").send_keys("selenium")
#driver.find_element_by_xpath("//a[contains(text(),'新闻')]").click()
#driver.find_element_by_xpath("//a[@href='http://news.baidu.com']").click()
time.sleep(5)
driver.quit()

通过安装firebug和xpath checker:copy xpth 和copy css path辅助学习理解xpth和css定位方式

0 0
原创粉丝点击