通过 Selenium VBA 启动 Chrome 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41591881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:52:02  来源:igfitidea点击:

Issue in launching Chrome via Selenium VBA

vbagoogle-chromeselenium

提问by Prem

I have tried to launch Chrome browser via Selenium VBA by using the below code. I am getting this error when executing the code "WebRequestError The underlying connection was closed: An unexpected error occurred on a receive." But IE browser is working fine.

我尝试使用以下代码通过 Selenium VBA 启动 Chrome 浏览器。执行代码“WebRequestError 底层连接已关闭:接收时发生意外错误”时出现此错误。但是 IE 浏览器工作正常。

Sub samp()
Dim drv As New Selenium.WebDriver
drv.Start "Chrome"
drv.Get "www.google.com"
End Sub

回答by Unicco

I fixed this by installing the latest ChromeDriver, and replacing the .exe-file with the file located in my AppData.

我通过安装最新的 ChromeDriver 解决了这个问题,并将 .exe 文件替换为位于我的 AppData 中的文件。

Requirements

要求

Steps

脚步

  1. Download latest WebDriver from: https://sites.google.com/a/chromium.org/chromedriver/downloads
  2. Open folder C:\Users\ Username\AppData\Local\SeleniumBasic
  3. Replace chromedriver.exe with existing file
  1. 从以下位置下载最新的 WebDriver:https: //sites.google.com/a/chromium.org/chromedriver/downloads
  2. 打开文件夹 C:\Users Username\\AppData\Local\SeleniumBasic
  3. 用现有文件替换 chromedriver.exe

Example

例子

Now this example code below works as intended

现在,下面的示例代码按预期工作

Sub driver()
    Dim selenium As New selenium.WebDriver

    selenium.Start "chrome", "http://google.com"
    selenium.Get "/"

End Sub