Drkcore

14 10 2011 Python Selenium Tweet

PythonでSelenium2.0のWebDriverを動かす

seleniumも覚えようかなぁとmacbook(10.5)で触ってみた。

selenium2.8とselenium 2.8.1のpythonモジュールではfirefoxが立ち上がらずに死ぬので、firefoxで動かすことに固執せずにとっとと諦めてchromeでやってみた。

Chromeで動かす場合にはchromedriverというものをダウンロードしてきて、適切な場所に配置(Macだと/Applications/Google Chrome.app/Contents/MacOS/)する必要があります。

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Chrome()
browser.get("http://www.yahoo.com")
assert "Yahoo!" in browser.title
elem = browser.find_element_by_name("p")
elem.send_keys("seleniumhq" + Keys.RETURN)
time.sleep(0.2)
try:
    browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
except NoSuchElementException:
    assert 0, "can't find seleniumhq"
browser.close()

というわけで触りだけ。

FitNesse+Selenium+Jenkinsによるテストケース継続的インテグレーションなんて素敵な匂いがしますな。

pythonで動かせるんだったらnosetestと一緒にごにょごにょすればそのままJenkinsと連携できそうな気もするが。

追記 11.10.14

でもって、selenium-server-standalone-2.8.0.jarを

:::sh java -jar selenium-server-standalone-2.8.0.jar

ってな感じで起動しておいて、以下のスクリプトを動かす

って書いてたけど、Chrome使う場合は別に動かす必要なかった。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021