当前位置:首页 > python > 正文内容

python selenium find_element_by_xpath 方法已经被弃用的解决办法

zhangsir3年前 (2022-10-27)python464

背景:


在使用最新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提供,第二个参数为定位的具体方式值


zhangsir版权k3防采集https://mianka.xyz

扫描二维码推送至手机访问。

版权声明:本文由zhangsir or zhangmaam发布,如需转载请注明出处。

本文链接:http://mianka.xyz/post/50.html

标签: pythonselenium
分享给朋友:

“python selenium find_element_by_xpath 方法已经被弃用的解决办法” 的相关文章

在Linux操作系统上使用selenium库

安装selenium模块命令:pip3 install selenium安装chrome命令:yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64....

Python怎么获取命令行参数

输入:“ import sys”,导入 sys 模块。插入语句:“print(sys.argv)”,打印获取的命令行参数。...

python 爬虫 报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0x8b in position”解决方案

发现报错“UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1:invalid start byte”,方法一:根据报错提示,错误原因有一条是这样的:“'Accept-Encodi...

计算机学习视频教程

人工智能机器学习:Python&R实践课程介绍:https://www.aihorizon.cn/1百度网盘地址: https://pan.baidu.com/s/1a743NTKFRjsgexMTagWooA?pwd=e39j动手使用Python进行自然语言处理(NLP)课程介绍:http...

Linux系统下使用Python+selenium+谷歌浏览器下载文件

from seleniumwire import webdriver import time ch_options = webdriver.ChromeOptions() ch_options.add_argument("-...