小编use*_*303的帖子

Selenium ChromeDriver使用浏览器代理无头运行Chrome 59时出现未知错误

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

执行代码时出现以下异常。初始化驱动程序时抛出异常

当我在注释无头选项(options.addArguments(“ headless”))后重新运行脚本时,它显示Chrome并运行良好,但我的目标是以无头方式运行它。您能否提供解决我的问题的想法?

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

步骤如下:在Mac上,我将Scala与SBT一起使用。Chrome 59 beta版ChromeDrive 2.29发布版本。

添加了以下依赖

  • “ org.seleniumhq.selenium”%“ selenium-chrome-driver”%“ 3.4.0”
  • “ org.seleniumhq.selenium”%“硒支持”%“ 3.4.0”
  • “ net.lightbody.bmp”%“浏览器核心”%“ 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 …
Run Code Online (Sandbox Code Playgroud)

beta headless selenium-chromedriver browsermob-proxy

5
推荐指数
1
解决办法
1493
查看次数