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