1

I am running a java webapp in Apache Tomcat/10.0.23 on a remote server which implements selenium chromedriver. However when I create the web driver it returns a HTTP Status 500 – Internal Server Error but in the logs is shows ChromeDriver was started successfully.

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

Google-chrome version: 110.0.5481.77

Chromedriver location: /usr/bin/chromedriver

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

Servlet:

import java.io.IOException;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet(name = "TestServlet", urlPatterns = { "/test" })
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
        ChromeOptions options = new ChromeOptions();
        options.setPageLoadStrategy(PageLoadStrategy.EAGER);
        options.addArguments("--headless=new");
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("--no-sandbox");
        WebDriver driver = new ChromeDriver(options);
        driver.get("https://www.google.com/");
        System.out.println("Page Title: " + driver.getTitle());
        driver.quit();
    }
}

Error:

<body>
    <h1>HTTP Status 500 – Internal Server Error</h1>
    <hr class="line" />
    <p><b>Type</b> Exception Report</p>
    <p><b>Message</b> 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.WebDriverException: 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.)
Build info: version: &#39;3.14.0&#39;, revision: &#39;aacccce0&#39;, time: &#39;2018-08-02T20:19:58.91Z&#39;
System info: host: &#39;ip-xxxxxxxxxxx;, ip: &#39;127.0.0.1&#39;, 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: driver.version: ChromeDriver
remote stacktrace: #0 0x5642671afd93 &lt;unknown&gt;
#1 0x564266f7e2d7 &lt;unknown&gt;
#2 0x564266fa6ab0 &lt;unknown&gt;
#3 0x564266fa2a3d &lt;unknown&gt;
#4 0x564266fe74f4 &lt;unknown&gt;
#5 0x564266fde353 &lt;unknown&gt;
#6 0x564266fade40 &lt;unknown&gt;
#7 0x564266faf038 &lt;unknown&gt;
#8 0x5642672038be &lt;unknown&gt;
#9 0x5642672078f0 &lt;unknown&gt;
#10 0x5642671e7f90 &lt;unknown&gt;
#11 0x564267208b7d &lt;unknown&gt;
#12 0x5642671d9578 &lt;unknown&gt;
#13 0x56426722d348 &lt;unknown&gt;
#14 0x56426722d4d6 &lt;unknown&gt;
#15 0x564267247341 &lt;unknown&gt;
#16 0x7f086945dea7 start_thread

    java.base&#47;jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    java.base&#47;jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    java.base&#47;jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.base&#47;java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:122)
    java.base&#47;java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    java.base&#47;java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    java.base&#47;java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    java.base&#47;java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    java.base&#47;java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    java.base&#47;java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    java.base&#47;java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    java.base&#47;java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    java.base&#47;java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
    org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:130)
    org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:181)
    org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:168)
    org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:157)
    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>

Log:

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

I've tried older versions of chrome driver and google chrome but get the same error.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

This error message...

The server encountered an unexpected condition that prevented it from fulfilling the request

...implies that ChromeDriver was unable to spawn a new Browsing Context i.e. session.

Your main issue is the incompatibility between the --headless=new argument/functionality and the Selenium version you are using.

  • You are using Selenium v3.14.0

    Build info: version: &#39;3.14.0&#39;
    
  • But you are trying to use the argument --headless=new

where as --headless=new argument/feature landed with Selenium v4.8.0


Solution

To use the argument --headless=new ensure that:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Maybe you have not installed browser. Install and try again.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 08 '23 at 22:16