当前位置: 首页 > 知识库问答 >
问题:

使用Browsermob代理运行chrome 59无头时发生Selenium chromeDrive未知错误

祝嘉懿
2023-03-14

我写了一个简单的Selenium测试(打开一个页面)的安全网站在无头模式使用Chrome59测试版。

我在执行代码时遇到以下异常。初始化驱动程序时引发异常

当我在注释了headless选项(options.addArguments(“headless”)后重新运行脚本时,它显示了Chrome并运行良好,但我的目标是将其作为headless运行。你能谈谈你对解决我的问题的看法吗?

例外:在端口4971上启动ChromeDriver 2.29.461585(0BE2CD95F834E9EE7C46BC7CF405B483F5AE83B),只允许本地连接。线程“main”组织中出现异常。openqa。硒。WebDriverException:未知错误:Chrome无法启动:异常退出(驱动程序信息:chromedriver=2.29.461585(0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),平台=Mac OS X 10.12.2 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:60.14秒构建信息:版本:“3.4.0”,版本:“未知”,时间:“未知”

以下是步骤:我在Mac上使用带有SBT的Scala。Chrome59测试版ChromeDrive 2.29发布版。

添加了以下依赖项

  • "org.seleniumhq.selenium"%"硒铬驱动器"%"3.4.0"
  • "org.seleniumhq.selenium"%"硒支持"%"3.4.0"
  • "net.lightbody.bmp"%"Browsermob-core"%"2.1.4"

Scala代码:

val username = "username"
val password = "password"
val domainname = "yoursecuredomain.com"

val browserMobProxyServer = new BrowserMobProxyServer()
browserMobProxyServer.start(0)

browserMobProxyServer.autoAuthorization(domainname, username, password, AuthType.BASIC)

val seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxyServer)

val options = new ChromeOptions()
options.addArguments("headless")
options.addArguments("--disable-gpu")
options.setBinary("""/Applications/Google Chrome.app/Contents/MacOS/Google Chrome""")

val desiredCapabilities = new DesiredCapabilities()
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options)
desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy)

val driver: WebDriver = new ChromeDriver(desiredCapabilities)

val baseUrlString = s"""https://$domainname"""

driver.navigate().to(baseUrlString)

Thread.sleep(3000)

println("title: " + driver.getTitle)

driver.quit()

browserMobProxyServer.abort()

共有1个答案

颛孙飞
2023-03-14

根据2.29 webdriver notes页面,它说

----------ChromeDriver v2.29(2017-04-04)----------

所以你必须降低你的chrome版本以兼容最新的chrome webdriver。

来源:https://chromedriver.storage.googleapis.com/2.29/notes.txt

 类似资料: