gpt4 book ai didi

java - 当 marionette 通过 Selenium 3.12.0 变为 false 时,无法找到与 Firefox 匹配的功能集

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:43 25 4
gpt4 key购买 nike

我已经正确设置了路径和firefox bin,但仍然不知道问题出在哪里。下面添加启动firefox驱动程序的代码:

System.setProperty("webdriver.gecko.driver", "/opt/config/x_conf_dir/geckodriver");
System.setProperty("webdriver.firefox.bin", "/opt/config/x_conf_dir/firefox-bin");
FirefoxOptions options = new FirefoxOptions();
options.addArguments("start-maximized");
options.addArguments("headless");
options.addArguments("window-size=1200,1100");
LOGGER.warn("Start initiating firefox driver");
WebDriver driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("https://stackoverflow.com");
LOGGER.warn("Page title is {}", driver.getTitle());
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/opt/config/x_conf_dir/screen.png"));

在java中启动firefox驱动程序时,当marionette转为false时,它会给出此异常,否则它会给出“无法找到匹配的功能集”。

org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'csrapp-02', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.77blibli.com', java.version: '1.8.0_101'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:132) ~[selenium-firefox-driver-3.12.0.jar:na]
at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:117) ~[selenium-firefox-driver-3.12.0.jar:na]
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79) ~[selenium-remote-driver-3.12.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543) ~[selenium-remote-driver-3.12.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207) ~[selenium-remote-driver-3.12.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130) ~[selenium-remote-driver-3.12.0.jar:na]
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125) ~[selenium-firefox-driver-3.12.0.jar:na]
at com.gdn.ext.catalog.rest.web.controller.api.crawler.ConfigurableCrawlerController.startFirefox(ConfigurableCrawlerController.java:278) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) [catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.4]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.4]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.4]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [catalina.jar:8.5.4]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [catalina.jar:8.5.4]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:632) [catalina.jar:8.5.4]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.5.4]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) [catalina.jar:8.5.4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [catalina.jar:8.5.4]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110) [tomcat-coyote.jar:8.5.4]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.4]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-coyote.jar:8.5.4]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-coyote.jar:8.5.4]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.4]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.4]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:21425/hub/status] to be available after 45002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) ~[selenium-remote-driver-3.12.0.jar:na]
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:130) ~[selenium-firefox-driver-3.12.0.jar:na]
... 50 common frames omitted
Caused by: java.util.concurrent.TimeoutException: null
at java.util.concurrent.FutureTask.get(FutureTask.java:205) ~[na:1.8.0_101]
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:180) ~[guava-22.0.jar:na]
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ~[selenium-remote-driver-3.12.0.jar:na]
... 51 common frames omitted

try {
System.setProperty("webdriver.gecko.driver", "/opt/config/x_conf_dir/geckodriver");
System.setProperty("webdriver.firefox.bin", "/opt/config/x_conf_dir/firefox-bin");
FirefoxOptions options = new FirefoxOptions();
options.addArguments("start-maximized");
options.addArguments("headless");
LOGGER.warn("Start initiating firefox driver");
WebDriver driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("https://stackoverflow.com");
LOGGER.warn("Page title is {}", driver.getTitle());
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/opt/config/x_conf_dir/screen.png"));

谢谢..

最佳答案

根据错误堆栈跟踪,您正在使用Selenium Java Client v3.12.0。所以你必须使用GeckoDriverma​​rionette作为强制措施。但默认情况下,ma​​rionette 设置为 true

正如您提到的marionatte 变为 false 因此您看到的错误为:

  • 工作代码:

    System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability("marionatte", true);
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dc);
    FirefoxDriver driver = new FirefoxDriver(opt);
    driver.get("https://stackoverflow.com");
  • 当您使用GeckoDriver时,marionatte 默认设置为true。在这种情况下,您还可以跳过 marionatte 功能,并使用以下解决方案:

    System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
    FirefoxDriver driver = new FirefoxDriver();
    driver.get("https://stackoverflow.com");
  • 您可以在 org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities while initiating Firefox v37 through Selenium v3.11.0 中找到详细讨论。

关于java - 当 marionette 通过 Selenium 3.12.0 变为 false 时,无法找到与 Firefox 匹配的功能集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491270/

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