2016年6月29日水曜日

selenium webdriverで古いバージョンのfirefox

firefoxの仕様がちょこちょこ変わるせいか定期的にwebdriverが動かなくなる。
いい加減にしろと言いたいとこだけど、
どうしようもないので、古いバージョンで動かすことにした。

環境: linux (ubuntu 16.04), ruby 2.3.0, selenium-webdriver

以前のバージョンの Firefox をインストールするには
から、linux用のちょっと前のバージョンをダウンロードして、適当に展開。

WebDriverを開く前に一行追加する。
(開くときにダウンロード先の指定とofxファイルのmime設定をしているが今回の件とは関係ない)


 ↓追加

 Selenium::WebDriver::Firefox.path = "展開したところ/firefox/firefox"

 profile = Selenium::WebDriver::Firefox::Profile.new
 profile["browser.download.useDownloadDir"] = true
 profile["browser.download.dir"] = '~/smbc'
 profile["browser.download.folderList"] = 2
 profile["browser.helperApps.neverAsk.saveToDisk"] = "application/x-ofx"
 driver = Selenium::WebDriver.for :firefox, :profile => profile