selenium模块报错os.path.basename(self.path), self.start_error_message)selenium.common.exceptions.

文章讲述了在使用Selenium操控Edge浏览器时遇到的WebDriver启动失败问题,提供了两种解决方案:一是通过`executable_path`指定驱动路径,二是确保浏览器版本是最新的,并配置环境变量指向正确的驱动程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、运行代码

driver = webdriver.Edge()
driver.get('https://www.baidu.com')

如果运行上述代码出现以下错误

Traceback (most recent call last):
  File "D:\pythonProject\python_bug\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "D:\python\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "D:\python\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/pythonProject/python_bug/Bug_Base/day11_selenium上/selenium_入门.py", line 6, in <module>
    driver = webdriver.Edge()
  File "D:\pythonProject\python_bug\venv\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 56, in __init__
    self.edge_service.start()
  File "D:\pythonProject\python_bug\venv\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687p

方法一 、 

加一个参数 executable_path='msedgedriver.exe'

driver = webdriver.Edge(executable_path='msedgedriver.exe')
time.sleep(2)
# 可以设置等待两秒启动
driver.get('https://www.baidu.com')

运行:

 

注意,浏览器版本必须是最新版本 !

 方法二 、 

找到微软浏览器打开设置找到如下标识:

检查是否是最新版本如果不是则则更新到最新,并下载相对应的微软驱动 配置环境变量,环境变量若不会配置可以看我前面的文章。 并且将下载的驱动程序放到微软浏览器的安装文件夹里,配置完成后退出重启下pycharn。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值