LoginSignup
3
2

More than 5 years have passed since last update.

MacでSeleniumはじめてみる

Posted at

Selenium

ブラウザ自動操作ツール
テスト効率化ツールなんて呼ばれてる
cURLを強力にしたものだと思ってる

SeleniumのAPI利用方法

Seleniumを使うには、python, java,ruby,etc...を用いる
さくっとはじめたかったので、pythonで試してみる

環境

OS: MacOS High Sierra
言語 : Python 2.7.10

導入

これだけ!

pip install selenium

firefoxでgoogleを開くサンプル

main.py
# -*- coding: utf-8 -*-
from selenium import webdriver
#firefoxを利用
driver = webdriver.Firefox()
#access to google
driver.get("http://google.com")
#googleの検索窓を取得(後述
element = driver.find_element_by_id( 'lst-ib')
#
element.send_keys("Hello Selenium!")

要素のみつけ方

SeleniumのAPIによると、idや名前で要素を取得できる
https://kurozumi.github.io/selenium-python/locating-elements.html

ちなみにfirefoxで、サイトの調べたい部分を右クリックして「要素を調査」を選択すると
idやnameが取得できるよ

Screen Shot 2018-06-02 at 23.15.57.png

Webのスクレイピングなどに利用してみる予定

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