LoginSignup
42
41

More than 5 years have passed since last update.

Selenium WebDriverでFirefox47を動かす方法

Last updated at Posted at 2016-06-12

2016年07月03日追記
Firefox47.0.1でGeckoDriverを利用しない場合にFirefoxが動かない不具合が修正されました。
https://www.mozilla.jp/firefox/47.0.1/releasenotes/

Firefox47.0.1に併せてSelenium WebDriverのバージョンも上がりました。
Firefox47.0.1を動かすには、Selenium WebDriverのバージョンアップも必要なようです。
(少なくとも、Rubyでは2.53.4にする必要がありました。)
http://www.seleniumhq.org/download/


Selenium WebDriverでFirefox47を動かすにはGeckoDriverが必要になりました。
https://github.com/seleniumhq/selenium/issues/2110

詳しく調査できておりませんが、最低限動作する状態にはできたため、その手順を記載します。

動作確認環境

  • Windows 7 64bit
  • Ruby 2.2.4
  • selenium-webdriver 2.53.0
  • Firefox 47
  • GeckoDriver 0.6.2(おそらく64bit OSのため新しいバージョンでは動作確認できず)

導入手順

参考
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

  1. GeckoDriverを以下のURLからダウンロード
    https://github.com/mozilla/geckodriver/releases

  2. GeckoDriverをwires.exeにリネーム

  3. wires.exeファイルを保存したフォルダのPATHを通す

  4. Visual C++ 2015 ランタイムをインストール
    https://www.microsoft.com/ja-jp/download/details.aspx?id=48145

  5. 下記URLを参考に既存のコードを修正
    https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

driver = Selenium::WebDriver.for :firefox, marionette: true

# Using RemoteWebDriver
caps = Selenium::WebDriver::Remote::Capabilities.firefox marionette: true
driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps

Rubyだと(?)管理者権限のないユーザの場合、Portの利用についてPermissionエラーが出る模様。
そのため、以下のモンキーパッチを適用

# Selenium::WebDriver.for :firefox, :port => 1024`では上手くいかなかったため暫定
# 参考
# https://github.com/SeleniumHQ/selenium/blob/selenium-2.53.0/rb/lib/selenium/webdriver/firefox/service.rb#L31
module Selenium
  module WebDriver
    module Firefox
      class Service
        DEFAULT_PORT        = 1026 # 任意
      end
    end
  end
end

制約

一部コマンドが正しく動作しない

詳細は下記URL参照
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status

フォームのSubmit driver.find_element(:name, "password").submit

代替案

driver.find_element(:name, "password").send_keys :enter

<select>に対する操作 Selenium::WebDriver::Support::Select.new(driver.find_element(:name, "select")).select_by(:text, "text")

代替案

driver.find_element(:name, "select").send_keys "text"
# プルダウン操作後にイベントが発生する場合、下記も必要な場合がある
driver.find_elemnet(:name, "select").send_keys :enter

firefoxのprofileを引数で指定できない?

以下のコードではエラーとなる

profile = Selenium::WebDriver::Firefox::Profile.new
driver = Selenium::WebDriver.for :firefox, :profile => profile
ArgumentError: unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile:0x0000000xxxxxxx @model=nil, @native_events=true, @secure_ssl=false, @untrusted_issuer=true, @load_no_focus_lib=false, @additional_prefs={}, @extensions={}>}
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/w3c_bridge.rb:85:in `initialize'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/firefox/w3c_bridge.rb:35:in `initialize'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/driver.rb:51:in `new'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/driver.rb:51:in `for'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver.rb:84:in `for'
        from (irb):7
        from C:/Ruby22-x64/bin/irb:11:in `<main>'
42
41
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
41