find_element_by_* commands are deprecated. Please use find_element() instead


今天要對之前的爬蟲項目進行維護,打開后發現警告如下:

 

 

 查看后發現這個方法將被棄用,包括find_element_by_id,xpath,class等方法,而會被find_element()方法所替代,而新的方法使用如下:

driver.find_element(By.ID, "txtUserName").clear()
driver.find_element(By.ID, "txtPassword").clear()
driver.find_element(By.ID,"txtUserName").send_keys(username)
driver.find_element(By.ID,"txtPassword").send_keys(password)
# ID,NAME,XPATH等寫法一樣

而這個By需要進行導入:

from selenium import webdriver
from selenium.webdriver.common.by import By

其使用方法並沒有什么太大的變化,把項目的舊方法進行更新就OK了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM