LoginSignup
2
6

More than 3 years have passed since last update.

FireFoxでSeleniumのテストを行うためのWebDriverの準備

Last updated at Posted at 2019-09-11

前回の続き。
Seleniumのテストを行うことを目標にWebDriverを準備する。

環境

  • macOS Majove (ver 10.14.6)
  • Python 2.7.10
  • FireFox Quantum 69.0 (64bit)
  • geckodriver 0.24.0 for macOS

pipでSeleniumをインストールする

前回入れたpipを用いてSeleniumをインストールする。

terminal
$ sudo pip3 install selenium
Password:************
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/Users/sf213471118/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/sf213471118/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: selenium in /Library/Python/2.7/site-packages/selenium-4.0.0a1-py2.7.egg (4.0.0a1)
Collecting urllib3 (from selenium)
  Downloading https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl (150kB)
     |████████████████████████████████| 153kB 263kB/s 
Installing collected packages: urllib3
Successfully installed urllib3-1.25.3

しっかり入ったことが確認できた。

バージョンは Selenium 4.0.0 alpha-1

geckodriverを配置

以下で最新のgeckodriverを入手。

本機はmacなのでgeckodriver-v0.24.0-macos.tar.gzをダウンロード。

解凍したものをpipと同じ階層に配置。今回用いたpip3は

/usr/local/bin/

にあるので、こちらでOK。

.pyファイルを書いて立ち上がるか確認

適当にpythonファイルを一つ作る。
今回は起動の確認なので中身は簡単にささっと。

Seleniumモジュールを呼んでFirefoxを指定する

OpenByFirefox.py
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://www.google.co.jp')

これをそのまま実行でGoogleの検索画面が開けばOK。

これでやっとSeleniumが使えそう(・ω・)

2
6
0

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
2
6