会话未创建异常:无法启动新会话,响应代码500在远程服务器上使用Apache Tomcat/10.0.23上的ChromeDriver

kmb7vmvb  于 2023-02-16  发布在  Apache
关注(0)|答案(1)|浏览(362)

我在一个实现了Selenium chromedriver的远程服务器上运行Apache Tomcat/10.0.23中的java webapp。每当我创建webdriver时,它都会返回HTTP状态500 -内部服务器错误。
谷歌浏览器位置:

/usr/bin/google-chrome /usr/share/man/man1/google-chrome.1.gz

谷歌 chrome 版:

110.0.5481.77

Chrome驱动程序位置:

/usr/bin/chromedriver

Chrome驱动程序版本:

110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481@{#839})

selenium

<dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-java</artifactId>
       <version>4.8.0</version>
</dependency>

错误:

<body>
    <h1>HTTP Status 500 – Internal Server Error</h1>
    <hr class="line" />
    <p><b>Type</b> Exception Report</p>
    <p><b>Message</b> Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start:
        crashed.</p>
    <p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.
    </p>
    <p><b>Exception</b></p>
    <pre>org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn&#39;t exist)
  (The process started from chrome location &#47;usr&#47;bin&#47;google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) 
Host info: host: &#39;ip-xxxxxxxxxx2&#39;, ip: &#39;127.0.0.1&#39;
Build info: version: &#39;4.8.0&#39;, revision: &#39;267030adea&#39;
System info: os.name: &#39;Linux&#39;, os.arch: &#39;amd64&#39;, os.version: &#39;5.10.0-21-cloud-amd64&#39;, java.version: &#39;11.0.15.1&#39;
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=new, --disable-dev-shm-usage, --no-sandbox], extensions: []}, pageLoadStrategy: eager}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=new, --disable-dev-shm-usage, --no-sandbox], extensions: []}, pageLoadStrategy: eager}}]
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
    org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:157)
    org.openqa.selenium.chromium.ChromiumDriver.&lt;init&gt;(ChromiumDriver.java:101)
    org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:82)
    org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:71)
    com.fourdcontrols.servlets.TestServlet.doGet(TestServlet.java:29)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:668)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
</pre>
    <p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p>
    <hr class="line" />
    <h3>Apache Tomcat/10.0.23</h3>
</body>

日志:

Starting ChromeDriver 110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481@{#839}) on port 3125
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
uxhixvfz

uxhixvfz1#

一个月一个月

A common cause for Chrome to crash during startup is running Chrome as **root** user (**administrator**) on Linux. While it is possible to work around this issue by passing--no-sandboxflag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.

参考文献

您可以在以下位置找到一些相关的详细讨论和文档:

相关问题