在旧版本的Firefox(v41.0)上运行Selenium(v3.4.0)

在浏览互联网之后,我失去了一些时间,我无法find解决scheme。 我目前正在尝试在旧版本的Firefox(这里是v41.0)上testing我的应用程序。 我正在通过Selenium的Docker 镜像 (v3.4.0)以及Firefox节点(v41.0)的docker镜像。

我知道对于老版本的Firefox,Geckodriver不兼容,但似乎有解决scheme使用

{ "marionette": true } 

Firefox节点完美地连接到网格。 我可以使用docker exec -it <container-id> bash连接到它,但运行testing时出现问题。

我仍然试图find它,但我被封锁了。 这里是Dockerfile的代码:hub.docker.com/r/selenium/node-firefox/~/dockerfile/用于Firefox节点,这里是testing代码(使用MochaJS)。

 test.it("should redirect to Google with FIREFOX 41.0", () => { var firefoxCap = Capabilities.firefox(); firefoxCap.set('marionette', true); driver = new webdriver.Builder() .usingServer(CONSTANTS.SELENIUM_HUB) .withCapabilities(firefoxCap) .build(); driver.get(CONSTANTS.GOOGLE_URL); driver.wait(until.titleIs(CONSTANTS.GOOGLE_TITLE)); driver.wait(until.elementLocated(By.name(CONSTANTS.GOOGLE_SEARCH_KEY))).sendKeys(CONSTANTS.GOOGLE_SEARCH_VALUE); driver.findElement(By.name(CONSTANTS.GOOGLE_SEARCH_BUTTON_NAME)).click(); driver.wait(until.titleIs(CONSTANTS.GOOGLE_SEARCH_TITLE)); driver.wait(until.elementLocated(By.tagName(CONSTANTS.GOOGLE_RES_LINK))).click(); driver.wait(until.titleIs(CONSTANTS.GOOGLE_TITLE)); driver.quit(); }); 

这里的日志

 ~/dev/selenium-grids/src$ mocha --timeout 30000 tests.js Starting the tests... Work with REMOTE URL 1) should redirect to Google with FIREFOX 41.0 0 passing (6s) 1 failing 1) Work with REMOTE URL should redirect to Google with FIREFOX 41.0: WebDriverError: Missing 'marionetteProtocol' field in handshake Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'd4b3266d29f4', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0_131' Driver info: driver.version: FirefoxDriver remote stacktrace: stack backtrace: 0: 0x5787ed - backtrace::backtrace::trace::h59229d13f6a8837d 1: 0x578942 - backtrace::capture::Backtrace::new::h23089c033eded8f0 2: 0x450aec - geckodriver::marionette::MarionetteHandler::create_connection::h6f7058fccafe4367 3: 0x425c32 - <webdriver::server::Dispatcher<T, U>>::run::h8f5348b8f5f7c053 4: 0x40b22c - std::panicking::try::do_call::hb67c6fb6bcd96195 5: 0x5dc20a - panic_unwind::__rust_maybe_catch_panic at /checkout/src/libpanic_unwind/lib.rs:98 6: 0x41b943 - <F as alloc::boxed::FnBox<A>>::call_box::h4100941edc372034 7: 0x5d48a4 - alloc::boxed::{{impl}}::call_once<(),()> at /checkout/src/liballoc/boxed.rs:650 - std::sys_common::thread::start_thread at /checkout/src/libstd/sys_common/thread.rs:21 - std::sys::imp::thread::{{impl}}::new::thread_start at /checkout/src/libstd/sys/unix/thread.rs:84 at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:517:15) at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:509:13) at doSend.then.response (node_modules/selenium-webdriver/lib/http.js:441:30) at <anonymous> at process._tickCallback (internal/process/next_tick.js:169:7) From: Task: WebDriver.createSession() at Function.createSession (node_modules/selenium-webdriver/lib/webdriver.js:777:24) at Function.createSession (node_modules/selenium-webdriver/firefox/index.js:667:55) at createDriver (node_modules/selenium-webdriver/index.js:167:33) at Builder.build (node_modules/selenium-webdriver/index.js:629:16) at Context.test.it (tests_web.js:64:14) at runTest (node_modules/selenium-webdriver/testing/index.js:164:22) at node_modules/selenium-webdriver/testing/index.js:185:16 at new ManagedPromise (node_modules/selenium-webdriver/lib/promise.js:1085:7) at controlFlowExecute (node_modules/selenium-webdriver/testing/index.js:184:14) at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:3092:14) at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:3075:27) at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2982:25) at node_modules/selenium-webdriver/lib/promise.js:676:7 at <anonymous> From: Task: Work with REMOTE URL should redirect to Google with FIREFOX 41.0 at Context.ret (node_modules/selenium-webdriver/testing/index.js:183:10) Closing the tests 

当谷歌search的问题,因为“谷歌是你的朋友”,唯一的答案是“更新您的Firefox版本”或“降级您的Selenium版本”,但我不能。 有人能解释我如何使其工作? 即使一个解决方法将被接受。

谢谢

当您使用Mozilla Firefox 41.0Selenium 3.4.0一起使用时,您需要将您的geckodriver降级到版本v0.17.0v0.16.1v0.16.0

以下是最近宣布的依赖关系:

geckodriver v0.18.0现在推荐Firefox 53 and greater

geckodriver v0.16.0只与Selenium 3.4 and greater兼容

最后,假设geckodriver.exe绝对path在您的System/User Path您必须明确地将marionette属性设置为false (必需)

您的代码块将如下所示:

 test.it("should redirect to Google with FIREFOX 41.0", () => { var firefoxCap = Capabilities.firefox(); firefoxCap.set('marionette', false); driver = new webdriver.Builder() .usingServer(CONSTANTS.SELENIUM_HUB) .withCapabilities(firefoxCap) .build(); 

Java代码打开传统的Mozilla Firefox 47.0.1(geckodriver v0.16.1):

 import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class Opening_FIREFOX_legacy { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver-v0.16.1-win64\\geckodriver.exe"); DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setCapability("firefox_binary", "C:\\Program Files\\Mozilla Firefox47\\firefox.exe"); dc.setCapability("marionette", false); WebDriver driver = new FirefoxDriver(dc); driver.manage().window().maximize(); driver.get("https://google.com"); } } 

Python代码打开传统的Mozilla Firefox 47.0.1(geckodriver v0.18.0):

 from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver.common.desired_capabilities import DesiredCapabilities binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox47\firefox.exe') caps = DesiredCapabilities().FIREFOX caps["marionette"] = False driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe") driver.get('https://stackoverflow.com')