gpt4 book ai didi

node.js - 为什么 Chrome 在尝试在 Selenium 下运行 Chromedriver 时无法启动?

转载 作者:搜寻专家 更新时间:2023-10-31 22:56:14 26 4
gpt4 key购买 nike

所以我之前有一个 Chromedriver/Selenium 设置可以工作,但现在试图在一台新机器(64 位 Linux)上安装所有东西,它给我带来了问题,并没有真正告诉我是什么问题。

我正在使用带有 nodejs 的 Selenium 独立服务器版本 2.37.0 和谷歌上可用的最新版本的 Chromedriver(我还尝试了 Chromedriver 2.0,这是我之前使用过的早期版本,结果相同)。

如下面的输出所示,当我尝试使用 webdriver 运行脚本时,我收到一个错误,其中包括:Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start:异常退出。我没有从 chromedriver 获得日志输出,只有 Selenium(有错误)和 Node.js(试图运行测试脚本)的输出。

谁能告诉我我在这里做错了什么?

编辑:我忘了补充一点,在失败后有一个 Chromedriver 正在运行的进程,所以那部分没问题,我的 Chrome 可执行文件确实位于/etc/bin/google-chrome,就像 Chromedriver 希望的那样。

输出:

一旦我启动并运行了 selenium,我就尝试运行一个包含以下内容的简单测试脚本:

var webdriverjs = require("webdriverjs");
var client = webdriverjs.remote({desiredCapabilities:{browserName:"chrome"}}); // to run in chrome
client
.init()
.url("https://github.com/")
.end();

运行测试脚本的 Node.js 控制台输出如下所示:

[1;33m=====================================================================================[0m

Selenium 2.0/webdriver protocol bindings implementation with helper commands in nodejs by Camilo Tapia.
For a complete list of commands, visit [1;32mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol[0m.
Not all commands are implemented yet. visit [1;32mhttps://github.com/Camme/webdriverjs[0m for more info on webdriverjs.

[1;33m=====================================================================================[0m

[1;30m[21:31:09]: [0m [0;35mCOMMAND [0mPOST "/wd/hub/session"
[1;30m[21:31:09]: [0m [0;33mDATA [0m{"desiredCapabilities":{"browserName":"chrome","version":"","javascriptEnabled":true,"platform":"ANY"},"sessionId":null}


[1;30m[21:31:32]: [0m [1;31mERROR [0mCOULDNT GET A SESSION ID
[1;30m[21:31:32]: [0m Exiting process with 1

最后,Selenium 在启动时和尝试运行脚本时的输出如下。出于某种原因,我根本没有收到 chromedriver.log 文件。

java -jar /usr/local/automation/framework/selenium/selenium-server-standalone-2.37.0.jar -Dwebdriver.chrome.driver='/usr/local/automation/framework/selenium/chromedriver' &
[1] 21293
ubuntu@ip-10-0-0-35:/usr/local/automation/framework/selenium$ Nov 15, 2013 9:30:31 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Setting system property webdriver.chrome.driver to /usr/local/automation/framework/selenium/chromedriver
21:30:32.240 INFO - Java: Oracle Corporation 23.5-b02
21:30:32.241 INFO - OS: Linux 3.2.0-48-virtual amd64
21:30:32.289 INFO - v2.37.0, with Core v2.37.0. Built from revision a7c61cb
21:30:32.586 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPhone, version=}] does not match with current platform: LINUX
21:30:32.626 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
21:30:32.774 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPad, version=}] does not match with current platform: LINUX
21:30:32.913 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
21:30:32.918 INFO - Version Jetty/5.1.x
21:30:32.919 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
21:30:32.920 INFO - Started HttpContext[/selenium-server,/selenium-server]
21:30:32.920 INFO - Started HttpContext[/,/]
21:30:32.968 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@3b3d8503
21:30:32.968 INFO - Started HttpContext[/wd,/wd]
21:30:32.974 INFO - Started SocketListener on 0.0.0.0:4444
21:30:32.975 INFO - Started org.openqa.jetty.jetty.Server@3e724328

ubuntu@ip-10-0-0-35:/usr/local/automation/framework/selenium$ 21:31:10.116 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=true, browserName=chrome, version=}] at URL: /session)
21:31:10.164 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=chrome, version=}]
Starting ChromeDriver (v2.6.232917) on port 17624
[0.797][WARNING]: PAC support disabled because there is no system implementation
21:31:32.375 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:176)
at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:112)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:89)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:104)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:63)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:205)
at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(JsonHttpRemoteConfig.java:192)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:139)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:914)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:72)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:215)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
... 9 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.6.232917,platform=Linux 3.2.0-48-virtual x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.99 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)
... 14 more
21:31:32.413 WARN - Exception: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.6.232917,platform=Linux 3.2.0-48-virtual x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.99 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.chrome.ChromeDriver

最佳答案

好的,在发布了所有这些之后,我才发现我做错了什么!

问题是我通过 SSH 从一个终端启动 selenium,然后通过 VNC 从桌面上的终端运行测试脚本。显然 Selenium、WebdriverJS 或 Chromedriver 不喜欢这样。

当我从桌面上的终端启动 Selenium 并运行测试脚本时,它工作正常。

关于node.js - 为什么 Chrome 在尝试在 Selenium 下运行 Chromedriver 时无法启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20011554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com