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)

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

相关推荐
kylezhao201910 小时前
C#中 Invoke、begininvoke、InvokeRequired的详细讲解和三者之间的区别
开发语言·c#
SCBAiotAigc10 小时前
2026.2.25:conda与uv并存时,如何取消base激活
人工智能·python·conda·uv
wanderful_10 小时前
Django 模拟支付功能开发:踩坑与闭环实现
后端·python·django
bubiyoushang88810 小时前
基于遗传算法的LQR控制器最优设计算法
开发语言·算法·matlab
YouGIS顽石工坊10 小时前
坐标转换服务私有化部署指南 - 源码与Docker两种方案
python·restful·docker镜像·python源码·pyproj·坐标转换服务·高斯克吕格投影
2301_7965125210 小时前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Pagination 分页(绑定当前页码)
javascript·react native·react.js·ecmascript·harmonyos
谢尔登10 小时前
深入React19任务调度器Scheduler
开发语言·前端·javascript
hoiii18710 小时前
MATLAB中LSSVM工具包及简单例程详解
开发语言·matlab
mingren_131410 小时前
SDL3配置及基本使用(完整demo)
开发语言·c++·音视频
李可以量化10 小时前
【Python 量化入门】AKshare 保姆级使用教程:零成本获取股票 / 基金 / 期货全市场金融数据
开发语言·python·金融·qmt·miniqmt·量化 qmt ptrade