Java Selenium 3.5.3 - 无效的moz:firefoxOptions字段成员

时间:2017-09-18 07:25:26

标签: java firefox selenium-webdriver geckodriver

Selenium升级后出现这些错误。

系统

  • 版本:geckodriver-v0.18.0
  • 平台:Linux / ubuntu 1704
  • Firefox:Firefox 55.0.3
  • 硒:3.5.3

堆栈跟踪

> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: Exception in thread "main
> org.openqa.selenium.InvalidArgumentException: Invalid
> moz:firefoxOptions field members Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url: Build
> info: version: 'unknown', revision: 'unknown', time: 'unknown' Sep 18
> 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: System info: host: 'costcoscraper-instance', ip:
> '10.0.98.2', os.name: 'Linux', os.arch: 'amd64', os.version:
> '4.10.0-32-generic', java.version: '1.8.0_131' Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url: Driver
> info: driver.version: Fi"refoxDriver Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url: remote
> stacktrace: stack backtrace: Sep 18 06:51:54 costcoscraper-instance
> startup-script: INFO startup-script-url:    0:           0x5787ed -
> backtrace::backtrace::trace::h59229d13f6a8837d Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:    1: 
> 0x578942 - backtrace::capture::Backtrace::new::h23089c033eded8f0 Sep
> 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    2:           0x4463cc -
> webdriver::error::WebDriverError::new::hd11f864b1fdf4510 Sep 18
> 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    3:           0x440ff3 - <core::iter::Map<I, F>
> as core::iter::iterator::Iterator>::next::h4f3cf544297176b2 Sep 18
> 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    4:           0x44baa3 -
> geckodriver::marionette::MarionetteHandler::create_connection::h6f7058fccafe4367
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    5:           0x425c32 -
> <webdriver::server::Dispatcher<T, U>>::run::h8f5348b8f5f7c053 Sep 18
> 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    6:           0x40b22c -
> std::panicking::try::do_call::hb67c6fb6bcd96195 Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:    7: 
> 0x5dc20a - panic_unwind::__rust_maybe_catch_panic Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:       
> at /checkout/src/libpanic_unwind/lib.rs:98 Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:    8: 
> 0x41b943 - <F as alloc::boxed::FnBox<A>>::call_box::h4100941edc372034
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url:    9:           0x5d48a4 -
> alloc::boxed::{{impl}}::call_once<(),()> Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:       
> at /checkout/src/liballoc/boxed.rs:650 Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:       
> - std::sys_common::thread::start_thread Sep 18 06:51:54 costcoscraper-instance startup-script: INFO startup-script-url:       
> at /checkout/src/libstd/sys_common/thread.rs:21 Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url:       
> - std::sys::imp::thread::{{impl}}::new::thread_start Sep 18 06:51:54 costcoscraper-instance startup-script: INFO startup-script-url:       
> at /checkout/src/libstd/sys/unix/thread.rs:84 Sep 18 06:51:54
> costcoscraper-instance startup-script: INFO startup-script-url: #011at
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.lang.reflect.Constructor.newInstance(Constructor.java:423) Sep 18
> 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:359)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:362)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
> Sep 18 06:51:54 costcoscraper-instance startup-script: INFO
> startup-script-url: #011at
> org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)

请帮助解决此问题。升级selenium版本和geckodriver和firefox后出现此问题。

这个更新的selenium 3.5.3代码以无头模式运行firefox。

FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "/home/karanpal_insonix/geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
Firefox driver = new FirefoxDriver();

1 个答案:

答案 0 :(得分:0)

要在 The type parameter <T> cannot be used with the `as` operator because it does not have a class type constraint nor a `class` constraint. 中发起 Mozilla Firefox ,您需要使用 Headless Mode 类并通过 FirefoxOptions 参数以及 --headless 二进制文件的绝对路径,即 firefox 。值得一提的是, firefox.exe 仍然在Mozilla Firefox Headless Mode,而且功能仅在 Development Stage 中提供。以下是示例代码块:

Mozilla Nightly Build

您可以在此处详细了解Mozilla Firefox in Headless Mode through Selenium 3.5.2 (Java)