我在一个实现Selenium chromedriver的远程服务器上运行Apache Tomcat/10.0.23中的Java Web应用程序。但是,当我创建Web驱动程序时,它返回HTTP状态500-内部服务器错误,但在日志中显示ChromeDriver已成功启动。
谷歌浏览器位置:/usr/bin/谷歌浏览器/usr/共享/man/man1/谷歌浏览器
谷歌 chrome 版:110.0.5481.77
Chrome驱动程序位置:/usr/bin/内存驱动程序
Chrome驱动程序版本:110.0.5481.77(65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/分支头端/5481@{#839})
小服务程序:
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();
}
}
错误:
<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't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'ip-xxxxxxxxxxx;, ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.0-21-cloud-amd64', java.version: '11.0.15.1'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x5642671afd93 <unknown>
#1 0x564266f7e2d7 <unknown>
#2 0x564266fa6ab0 <unknown>
#3 0x564266fa2a3d <unknown>
#4 0x564266fe74f4 <unknown>
#5 0x564266fde353 <unknown>
#6 0x564266fade40 <unknown>
#7 0x564266faf038 <unknown>
#8 0x5642672038be <unknown>
#9 0x5642672078f0 <unknown>
#10 0x5642671e7f90 <unknown>
#11 0x564267208b7d <unknown>
#12 0x5642671d9578 <unknown>
#13 0x56426722d348 <unknown>
#14 0x56426722d4d6 <unknown>
#15 0x564267247341 <unknown>
#16 0x7f086945dea7 start_thread
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.base/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/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
java.base/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.<init>(RemoteWebDriver.java:130)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
org.openqa.selenium.chrome.ChromeDriver.<init>(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>
- 日志:**
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.
我试过旧版本的chrome驱动程序和谷歌浏览器,但得到相同的错误.
1条答案
按热度按时间qvk1mo1f1#
此错误消息...
...表示ChromeDriver无法生成新的 * 浏览上下文 *,即google-chrome会话。
您的主要问题是
--headless=new
参数/功能与您正在使用的Selenium版本之间的不兼容。--headless=new
***其中,***
--headless=new
***参数/功能使用***Selenium v4.8.0***溶液
要使用参数
--headless=new
,请确保: