背景:
在使用最新3.10.4Python版本时候,用selenium进行xpath定位元素,编译器提示:
DeprecationWarning:
find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead driver.find_element_by_xpath('//*[@id="app"]/section/main/div/button[1]').click()
find_element_by_xpath 方法已经被弃用,请使用新的导入By包的方法,这里简单记一下导入By包后如何使用新的方法进行xpath定位
1.导入by包:
from selenium.webdriver.common.by import By
By类的方法:
1.find_element(By.XPATH, ‘xpath路径’)
2.需要两个参数,第一个参数为定位的类型,由By提供,第二个参数为定位的具体方式值

本文指导如何在Python Selenium 3.10.4中更新xpath定位方法,避免DeprecationWarning,通过导入By包并使用find_element(by=By.XPATH, value=...)实现新标准定位。

2万+

被折叠的 条评论
为什么被折叠?



