LoginSignup
69
80

More than 5 years have passed since last update.

Selenium ChromeDriver & PythonをMacで動かす準備メモ

Last updated at Posted at 2017-11-26

はじめに

  • Webアプリの受け入れ"簡易"試験を実施することになりまして
  • "簡易"なのでMac上に環境を構築しました。
  • 備忘のために手順をメモしておきます。

前提

ソフト バージョン
Mac Sierra 10.12.6
Python 3.6.3
Selenium 3.7.0
ChromeDriver 2.33
Chrome 61.0.3163.100

Seleniumインストール

pip install selenium

「そもそもpipが入っていない!」という方は
curl -kL https://bootstrap.pypa.io/get-pip.py | python
を実行してください。

ChromeDriverインストール

brew install chromedriver

「そもそもbrewが入っていない!」という方は
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
を実行してください。

brewを使わない or Mac以外の方は以下サイトの「Latest Release」のバージョンのダウンロード画面から
環境に合うものをダウンロード・インストールします。
https://sites.google.com/a/chromium.org/chromedriver/downloads

テストプログラムの実行

「Chromeを起動して"Selenium"とGoogle検索して、Seleniumの公式サイトを開く。」
というテストプログラムを実行してみます。

selenium-test.py
# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep

# ブラウザを開く。
driver = webdriver.Chrome()
# Googleの検索TOP画面を開く。
driver.get("https://www.google.co.jp/")
# 検索語として「selenium」と入力し、Enterキーを押す。
driver.find_element_by_id("lst-ib").send_keys("selenium")
driver.find_element_by_id("lst-ib").send_keys(Keys.ENTER)
# タイトルに「Selenium - Web Browser Automation」と一致するリンクをクリックする。
driver.find_element_by_link_text("Selenium - Web Browser Automation").click()
# 5秒間待機してみる。
sleep(5)
# ブラウザを終了する。
driver.close()

参考サイト

69
80
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
69
80