【hacker的错误集】DeprecationWarning: find_element_by_* commands are deprecated.

简介: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead。依旧是使用单词意思分析报错原因

cdff581d333e4896a29de68022a7b697.jpg

报错内容



报错代码:


from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
time.sleep(1)
driver.find_element_by_id('kw').send_keys('python')
time.sleep(1)
driver.find_element_by_id('su').click()

ea7edf308be0490fa5c90031644f5fd7.png


报错分析



DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead。依旧是使用单词意思分析报错原因


DeprecationWarning 弃用警告

command命令

instead代替


分析可以得出:弃用警告:find_elment_by_命令已弃用。请使用find_element()代替

居然:那这应该怎么替换啊?

hacker:按照报错提示做就好了


解决方案



在selenium中的元素定位方式find_elment_by_*已被弃用,执行时会出现异常

这时我们需要使用新的方法代替(find_elment)


第一步:先导入By模块


from selenium.webdriver.common.by import By


第二步:替换为find_elment()方法


driver.find_element(By.ID, 'kw')


完整代码:


from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
time.sleep(1)
driver.find_element(By.ID, 'kw').send_keys('python')
time.sleep(1)
driver.find_element(By.ID, 'su').click()

bceeb62bf7aa456881a765ff57c30d5b.jpg


相关文章
|
6月前
|
安全
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
|
6月前
|
JavaScript 前端开发
We‘re sorry but xxxxxx doesn‘t work properly without JavaScript enabled.
We‘re sorry but xxxxxx doesn‘t work properly without JavaScript enabled.
|
8月前
杭电2095(find your present (2))
杭电2095(find your present (2))
43 0
|
8月前
|
JavaScript
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
|
Web App开发 JavaScript 前端开发
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled. Please enable it to continue 这个错误提示表明目标网页要求启用JavaScript才能正常工作,而默认情况下,Selenium WebDriver是启用JavaScript的。如果遇到此错误,请按照以下步骤尝试解决问题
761 0
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled
错误解决办法:‘NULL’ was not declared in this scope
错误解决办法:‘NULL’ was not declared in this scope
270 0
|
数据采集 Python
|
机器学习/深度学习 Java
HDOJ 2095 find your present (2)
HDOJ 2095 find your present (2)
116 0
HDOJ 2095 find your present (2)
关于Unable to find a @SpringBootConfiguration错误解决方法
SpringBoot项目上跑测试类,加上@SpringBootTest运行报错,其中一种错误就是未加载到启动类,导致整个启动类挂了,详情看下方内容
531 0
关于Unable to find a @SpringBootConfiguration错误解决方法
|
安全 Linux
linux系统下,警告:warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration] 和 warning: the `gets' function is dangerous and should
字符数组 的英文名字是 char [] gets()函数的基本用法为:char *gets(char *s); 该函数的参数是一个字符数组,该函数的返回值也是一个字符数组。 linux下的代码如下: 1 #include 2 3 int main() 4 { 5    c...
2022 0

热门文章

最新文章

下一篇
开通oss服务