Excel VBA调用Selenium打开Chrome登录网站时遇运行时错误33求助
解决VBA调用Selenium ChromeDriver时的Run-time error 33问题
Run-time error 33通常和ChromeDriver与浏览器兼容性、路径配置或权限有关,以下是具体排查和解决方法:
1. 匹配ChromeDriver与Chrome浏览器版本
- 打开Chrome,点击右上角三个点→设置→关于Chrome,查看当前浏览器主版本号(比如118.x)
- 下载对应主版本的ChromeDriver,确保两者大版本完全一致
- 将ChromeDriver放到Chrome安装目录(如
C:\Program Files\Google\Chrome\Application),或系统PATH环境变量包含的路径中,也可在代码里显式指定驱动路径
2. 显式指定Chrome和ChromeDriver路径
在代码中添加路径指定,避免系统找不到对应程序:
Public Sub seleniumtutorial() Dim bot As New Selenium.ChromeDriver Dim username As String Dim password As String Dim URL As String ' 根据你的实际安装路径修改 bot.SetBinary "C:\Program Files\Google\Chrome\Application\chrome.exe" bot.SetDriverPath "C:\WebDrivers\chromedriver.exe" URL = "http://auto.lotus.ir/faces/pages/security/login.xhtml?ignoreAutoLogin=true&message=enableAutoLogin" username = "lili" password = "123456" bot.Get URL ' 等待页面加载完成,避免元素未就绪 bot.Wait 2000 bot.FindElementByName("j_username").SendKeys username bot.FindElementByName("j_password").SendKeys password bot.FindElementById("Submit").Click bot.Quit End Sub
3. 检查权限问题
- 右键Excel文件,选择「以管理员身份运行」后再执行代码
- 右键ChromeDriver文件→属性→安全,确认当前用户拥有「读取和执行」权限
4. 重新确认Selenium引用
- 打开VBA编辑器→工具→引用,取消勾选「Selenium Type Library」后重新勾选,确保引用生效
内容的提问来源于stack exchange,提问作者Mohamad Noruznia
相关产品推荐
相关产品推荐

