【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


相关文章
|
4月前
|
安全
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月前
|
编译器 C语言
gcc编译警告:warning: suggest parentheses around assignment used as truth value
gcc编译警告:warning: suggest parentheses around assignment used as truth value
323 0
|
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的。如果遇到此错误,请按照以下步骤尝试解决问题
746 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
262 0
|
数据采集 Python
【hacker的错误集】ValueError: I/O operation on closed file
ValueError: I/O operation on closed file.依旧是使用单词意思来分析报错原因
430 0
【hacker的错误集】ValueError: I/O operation on closed file
【hacker的错误集】AttributeError:module ‘requests‘ has no attribute ‘get‘
今天,在给一个粉丝远程解决技术问题的时候,发现的一个大家可能都会犯的错误
166 0
【hacker的错误集】AttributeError:module ‘requests‘ has no attribute ‘get‘
关于Unable to find a @SpringBootConfiguration错误解决方法
SpringBoot项目上跑测试类,加上@SpringBootTest运行报错,其中一种错误就是未加载到启动类,导致整个启动类挂了,详情看下方内容
499 0
关于Unable to find a @SpringBootConfiguration错误解决方法
|
Shell Python
安装 AWS Command Line Interface 失败 Could not find a version that satisfies the requirement awscli
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79739281 ...
2014 0