【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


目录
相关文章
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
251 0
|
Ubuntu Unix Linux
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
问题提解决:ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhos
问题提解决:ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhos
|
11月前
成功解决Failed to execute stage ‘Setup validation’: Cannot locate gluster packages
成功解决Failed to execute stage ‘Setup validation’: Cannot locate gluster packages
|
网络安全 开发工具
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
836 0
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
|
数据采集 Python
【hacker的错误集】ValueError: I/O operation on closed file
ValueError: I/O operation on closed file.依旧是使用单词意思来分析报错原因
370 0
【hacker的错误集】ValueError: I/O operation on closed file
【hacker的错误集】AttributeError:module ‘requests‘ has no attribute ‘get‘
今天,在给一个粉丝远程解决技术问题的时候,发现的一个大家可能都会犯的错误
135 0
【hacker的错误集】AttributeError:module ‘requests‘ has no attribute ‘get‘
关于Unable to find a @SpringBootConfiguration错误解决方法
SpringBoot项目上跑测试类,加上@SpringBootTest运行报错,其中一种错误就是未加载到启动类,导致整个启动类挂了,详情看下方内容
408 0
关于Unable to find a @SpringBootConfiguration错误解决方法
Cannot find source code based button in SE24 - modification assistant
Cannot find source code based button in SE24 - modification assistant
137 0

热门文章

最新文章

  • 1
    流量控制系统,用正则表达式提取汉字
    25
  • 2
    Redis09-----List类型,有序,元素可以重复,插入和删除快,查询速度一般,一般保存一些有顺序的数据,如朋友圈点赞列表,评论列表等,LPUSH user 1 2 3可以一个一个推
    26
  • 3
    Redis08命令-Hash类型,也叫散列,其中value是一个无序字典,类似于java的HashMap结构,Hash结构可以将对象中的每个字段独立存储,可以针对每字段做CRUD
    25
  • 4
    Redis07命令-String类型字符串,不管是哪种格式,底层都是字节数组形式存储的,最大空间不超过512m,SET添加,MSET批量添加,INCRBY age 2可以,MSET,INCRSETEX
    27
  • 5
    S外部函数可以访问函数内部的变量的闭包-闭包最简单的用不了,闭包是内层函数+外层函数的变量,简称为函数套函数,外部函数可以访问函数内部的变量,存在函数套函数
    23
  • 6
    Redis06-Redis常用的命令,模糊的搜索查询往往会对服务器产生很大的压力,MSET k1 v1 k2 v2 k3 v3 添加,DEL是删除的意思,EXISTS age 可以用来查询是否有存在1
    30
  • 7
    Redis05数据结构介绍,数据结构介绍,官方网站中看到
    21
  • 8
    JS字符串数据类型转换,字符串如何转成变量,+号只要有一个是字符串,就会把另外一个转成字符串,- * / 都会把数据转成数字类型,数字型控制台是蓝色,字符型控制台是黑色,
    19
  • 9
    JS数组操作---删除,arr.pop()方法从数组中删除最后一个元素,并返回该元素的值,arr.shift() 删除第一个值,arr.splice()方法,删除指定元素,arr.splice,从第一
    19
  • 10
    定义好变量,${age}模版字符串,对象可以放null,检验数据类型console.log(typeof str)
    19