Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
chromedriver:无法执行二进制文件和通过Java将chromedriver Selenium的会话null上的严重转发新闻会话到远程_Java_Selenium_Google Chrome_Selenium Chromedriver_Google Chrome Headless - Fatal编程技术网

chromedriver:无法执行二进制文件和通过Java将chromedriver Selenium的会话null上的严重转发新闻会话到远程

chromedriver:无法执行二进制文件和通过Java将chromedriver Selenium的会话null上的严重转发新闻会话到远程,java,selenium,google-chrome,selenium-chromedriver,google-chrome-headless,Java,Selenium,Google Chrome,Selenium Chromedriver,Google Chrome Headless,我有一个使用selenium的服务,它使用chromeheadless模式启动chrome webdriver。该应用程序通过tomcat8启动。我可以在mac上本地运行该服务,而不会出现问题 但一旦我通过AWS Elastic Beanstalk将其部署到ec2节点,webdriver就无法正常启动: 28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperVa

我有一个使用selenium的服务,它使用chrome
headless
模式启动chrome webdriver。该应用程序通过
tomcat8
启动。我可以在mac上本地运行该服务,而不会出现问题

但一旦我通过AWS Elastic Beanstalk将其部署到ec2节点,webdriver就无法正常启动:

28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registerCustomer] in context with path [] threw exception
 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-31-16-234', ip: '172.31.16.234', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.97-74.72.amzn1.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
    at com.christina.insbot.factory.BrowserDriverFactory.createWebDriver(BrowserDriverFactory.java:64)
    at com.christina.insbot.service.InsBot.<init>(InsBot.java:86)
    at com.christina.insbot.service.servlet.RegisterCustomerService.doPost(RegisterCustomerService.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:685)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:13611/status] to be available after 20010 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
    ... 36 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
    ... 37 more
我启动webdriver的方式如下:

        ChromeOptions options = new ChromeOptions();
        // "--headless",
        options.addArguments("--disable-gpu", "--window-size=1920,1200",
                "--ignore-certificate-errors", "--silent");

        if (useHeadlessMode) {
            options.addArguments("--headless");
        }


        System.setProperty("webdriver.chrome.driver", EnvironmentInitialization.obtainChromeDriverPath());

        webDriver = new ChromeDriver(options);
此错误消息

28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registerCustomer] in context with path [] threw exception
 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-31-16-234', ip: '172.31.16.234', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.97-74.72.amzn1.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
/var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: /var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: cannot execute binary file
28-Feb-2019 03:32:48.926 SEVERE [Forwarding newSession on session null to remote] org.openqa.selenium.os.OsProcess.checkForError org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)
…表示您的程序无法在无头模式下启动/生成新的ChromeDriver服务

此外,此错误消息

28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registerCustomer] in context with path [] threw exception
 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-31-16-234', ip: '172.31.16.234', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.97-74.72.amzn1.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
/var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: /var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: cannot execute binary file
28-Feb-2019 03:32:48.926 SEVERE [Forwarding newSession on session null to remote] org.openqa.selenium.os.OsProcess.checkForError org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)
…表示您的程序无法执行chromedriver二进制文件,因此将null会话转发到RemoteWebServer


更多关于ChromeDriver和ChromeBrowser版本的信息将有助于我们更好地调试您的问题。但是,您需要注意以下几个事实:

  • 根据
    ——Linux系统和MacOS上不需要禁用gpu
    标志
  • 根据
    ——禁用gpu
    标志在Windows系统上也将变得不必要
  • 您正在使用“2017-12-01T18:33:54.468Z”的Selenium v3.8.1
  • 但是您的JDK版本要更新得多java.version:'1.8.0_191'
  • 几乎可以肯定,您的程序正试图以ROOT用户的身份生成ChromeDriver进程

解决方案
  • 将JDK升级到最新级别
  • 将硒升级到当前水平
  • 将ChromeDriver升级到当前级别
  • 将Chrome版本保持在Chrome v71-73级别之间。()
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • (仅限LinuxOS)在执行测试套件之前和之后
  • 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
  • 确保ChromeDriver位于指定位置
  • 确保ChromeDriver对非root用户具有可执行权限
  • 重新启动系统
  • 以非root用户身份执行
    @Test
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

琐事 您可以在以下内容中找到一些相关讨论:


感谢您提供详细的解决方案。我昨天晚上解决了这个问题,结果发现我没有在EC2节点上安装chrome,而且chrome webdriver版本也不适用于EC2实例。我已经升级到那个节点,安装了chrome并更新了chrome驱动程序,它可以正常工作。