You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Selenium.EdgeDriver执行自动化代码时出现自动化错误

Selenium EdgeDriver自动化错误排查方案(VBA环境)

问题重现

运行以下VBA代码时出现Selenium EdgeDriver自动化错误,单独运行edgedriver.exe提示启动成功,但Edge/Chrome自动化代码均报错:

Dim edge As New Selenium.EdgeDriver
Dim By As New By
Dim smartbuyURL As String
smartbuyURL = "http://bayer-t.procurement-eu.ariba.com" 'PROD: http://bayer.procurement-eu.ariba.com

With edge
    .Get smartbuyURL
End With

排查与解决步骤

1. 强制匹配驱动与浏览器版本

即使安装了最新组件,也需确认EdgeDriver与Edge浏览器的版本号、发布通道完全一致:

  • 打开Edge,输入edge://version/查看完整版本(如125.0.2535.98)和发布通道(稳定版/Dev版等)
  • 替换现有edgedriver.exe为对应版本的驱动,可在代码中明确指定驱动路径:
    Dim edge As New Selenium.EdgeDriver
    edge.SetDriverPath "C:\Path\To\Your\EdgeDriver" ' 替换为实际驱动文件夹路径
    edge.Get "http://bayer-t.procurement-eu.ariba.com"
    

2. 校验Selenium VBA库引用

  • 打开VBA编辑器(Alt+F11),进入「工具」→「引用」
  • 确保勾选的Selenium库为最新版本,无红色报错;若存在异常,先移除旧引用,重新添加最新版Selenium VBA库

3. 以管理员权限运行程序

右键点击你的Excel/Access文件,选择「以管理员身份运行」,避免系统权限限制导致驱动无法启动浏览器进程

4. 添加浏览器启动参数

针对企业内网网站的安全限制,添加启动参数绕过限制:

Dim edge As New Selenium.EdgeDriver
Dim options As New EdgeOptions
' 添加常用兼容性参数
options.AddArgument("--no-sandbox")
options.AddArgument("--disable-dev-shm-usage")
options.AddArgument("--start-maximized")
' 应用参数并启动
edge.SetEdgeOptions options
edge.Get "http://bayer-t.procurement-eu.ariba.com"

5. 检查系统环境变量

确保edgedriver.exe所在路径已添加到系统PATH环境变量中,或直接在代码中指定驱动路径(步骤1的方法)

注:因Chrome自动化也出现相同错误,优先排查权限、库引用、系统环境这类通用问题

内容的提问来源于stack exchange,提问作者Rafiq Imran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 14:53:39