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)

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

相关推荐
智者知已应修善业15 分钟前
【给定英文字符串统计最多小写最前输出】2023-2-27
c语言·开发语言·c++·经验分享·笔记·算法
咕白m62518 分钟前
通过 Python 在 PDF 中添加页面
python
wa的一声哭了30 分钟前
Linux服务器配置ssh免密登陆多台服务器、服务器别名配置
linux·运维·服务器·网络·arm开发·python·ssh
我的golang之路果然有问题40 分钟前
mac配置 unity+vscode的坑
开发语言·笔记·vscode·macos·unity·游戏引擎
铅笔小新z1 小时前
【C++】从理论到实践:类和对象完全指南(上)
开发语言·c++
rainFFrain1 小时前
qt显示类控件---QCalendarWidget
开发语言·qt
蓁蓁啊1 小时前
ARM交叉编译中编译与链接参数不一致导致的问题
开发语言·arm开发·嵌入式硬件
go_bai1 小时前
Linux-线程
linux·开发语言·c++·经验分享·笔记
咖啡の猫1 小时前
Python中的输出函数
开发语言·数据库·python
zzzsde2 小时前
【C++】二叉搜索树
开发语言·c++