satymale’s diary

日々の忘備録

SeleniumでFirefoxのテストができない時

Selenium.WebDriver(v3.0.0)でテストを行っていると、いつの段階か以下のエラーがでてテストが出来なくなりました。

型 'OpenQA.Selenium.DriverServiceNotFoundException' の例外が WebDriver.dll で発生しましたが、ユーザー コード内ではハンドルされませんでした

追加情報:The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases.

エラーの解消

エラーメッセージに従って、「https://github.com/mozilla/geckodriver/releases」からgeckodriverをダウンロードします。私の環境はWindows 64bitなので、 geckodriver-v0.11.1-win64.zipをダウンロードしました。

zipを解凍すると、geckodriver.exeが出てきます。
geckodriver.exeを任意のフォルダに配置し、環境変数のPATHに配置したフォルダのパスを追加します。

環境変数にパスを追加後、Visual Studioを再度立ち上げ直してテストを実行すると問題なくFirefoxを使ったテストが行えるようになります。