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)

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

相关推荐
爱学习的梵高先生6 分钟前
C++:基础知识
开发语言·c++·算法
oioihoii10 分钟前
C++对象生命周期与析构顺序深度解析
java·开发语言·c++
IMPYLH13 分钟前
Lua 的 tonumber 函数
开发语言·笔记·后端·junit·游戏引擎·lua
工会代表16 分钟前
使用 GitHub Actions 与 Docker 实现 CaptchaVision API 持续集成
python
cvyoutian24 分钟前
解决 PyTorch 大型 wheel 下载慢、超时和反复重下的问题
人工智能·pytorch·python
渴望成为python大神的前端小菜鸟32 分钟前
浏览器及其他 面试题
前端·javascript·ajax·面试题·浏览器
It's now40 分钟前
BeanRegistrar 的企业级应用场景及最佳实践
java·开发语言·spring
1024肥宅42 分钟前
手写 new 操作符和 instanceof:深入理解 JavaScript 对象创建与原型链检测
前端·javascript·ecmascript 6
毕设源码-赖学姐1 小时前
【开题答辩全过程】以 基于Java的小区物业管理系统APP的设计与实现为例,包含答辩的问题和答案
java·开发语言
繁华似锦respect1 小时前
C++ & Linux 中 GDB 调试与内存泄漏检测详解
linux·c语言·开发语言·c++·windows·算法