Python+Selenium 自动化实现实例-Xpath捕捉元素的几种方法


#coding=utf-8
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
time.sleep(5)
#id 定位
driver.find_element_by_xpath("//input[@id='kw']").send_keys("hello")
driver.find_element_by_xpath("//input[@id='su']").click()

#class 定位
driver.find_element_by_xpath("//input[@class='s_ipt']").send_keys("hujun")
driver.find_element_by_xpath("//*[@class='btn self-btn bg s_btn']").click()

#使用逻辑运算符
driver.find_element_by_xpath("//input[@id='kw' and @class='s_ipt']/span/input")

driver.quit()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM