find_element_by_id()方法的使用上。这个方法已经被弃用,建议使用find_element()方法替代。

python 复制代码
from selenium import webdriver
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)
url = 'https://www.baidu.com'
browser.get(url)
button = browser.find_element_by_id('su')
print(button)

修改后代码

python 复制代码
from selenium import webdriver
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)
url = 'https://www.baidu.com'
browser.get(url)
# 使用 find_element() 方法替代 find_element_by_id()
button = browser.find_element('id', 'su')
print(button)

报错原因:webdriver.Chrome()的参数路径错误。

修改后的代码:

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

path = 'chromedriver.exe'
service = Service(executable_path=path)
browser = webdriver.Chrome(service=service)

url = 'https://www.baidu.com'

browser.get(url)

# 使用 find_element() 方法替代 find_element_by_id()
button = browser.find_element('id', 'su')
print(button)

但是,虽然出现报错信息,但是有运行结果,可以修改代码,也可以不修改!!!

相关推荐
-dcr几秒前
50.智能体
前端·javascript·人工智能·ai·easyui
代码游侠5 分钟前
学习笔记——ESP8266 WiFi模块
服务器·c语言·开发语言·数据结构·算法
0和1的舞者6 分钟前
Python 中四种核心数据结构的用途和嵌套逻辑
数据结构·python·学习·知识
weixin_462446237 分钟前
Python 使用 PyQt5 + Pandas 实现 Excel(xlsx)批量合并工具(带图形界面)
python·qt·pandas
Hello.Reader8 分钟前
PyFlink Configuration 一次讲透怎么配、配哪些、怎么“调得快且稳”
运维·服务器·python·flink
行者9610 分钟前
Flutter跨平台开发适配OpenHarmony:进度条组件的深度实践
开发语言·前端·flutter·harmonyos·鸿蒙
云和数据.ChenGuang11 分钟前
Uvicorn 是 **Python 生态中用于运行异步 Web 应用的 ASGI 服务器**
服务器·前端·人工智能·python·机器学习
Hello.Reader11 分钟前
PyFlink Table API / DataStream API / UDF / 依赖管理 / 运行时模式一篇打通(含示例代码与避坑)
python·flink
DYS_房东的猫14 分钟前
《 C++ 零基础入门教程》第3章:结构体与类 —— 用面向对象组织代码
开发语言·c++
hui函数15 分钟前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有仓库认证失败 401 Unauthorized 问题
python·bug·pip