Action disabled: source

Selenium

since 2012-05-08

phpunit の記事で PHP 環境のことを書いた。

ここでは Python 環境のことを書く。

環境は MacPorts on Snow Leopard (まだLionにしていない)。。

sudo port install python27
sudo port install py27-pip
sudo pip-2.7 install selenium

http://ore.saizensen.net/archives/487

とりあえず http://pypi.python.org/pypi/selenium に書いてあるサンプルは

#!/usr/bin/env python2.7

を先頭行に追加して chmod 755 して動作を確認した。

API ドキュメント http://selenium.googlecode.com/svn/trunk/docs/api/py/api.html

assertXXX がないが、実は assert は Python の statement をそのまま使う。

assert "Yahoo!" in browser.title

わかってしまえば PHP より美しい。

selenium.selenium のところに Element Locator の仕様が書かれている。

Can't load the profile

since 2012-08-08

環境は Mountain Lion を使っている。

下記のエラー(Can't load the profile)が出た:

$ python2.7 test_selenium.py 
Traceback (most recent call last):
  File "test_selenium.py", line 6, in <module>
    browser = webdriver.Firefox()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 51, in __init__
    self.binary, timeout),
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
    self._wait_until_connectable()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 86, in _wait_until_connectable
    self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: "Can't load the profile. Profile Dir: /var/folders/pf/n139yg5d44n8fvr6b04s6vkh0000gn/T/tmpC4C5yY Firefox output: *** LOG addons.xpi: startup\n*** LOG addons.xpi: Skipping unavailable install location app-system-share\n*** LOG addons.xpi: checkForChanges\n*** LOG addons.xpi: No changes found\n" 

下記の手順でアップデートしたら解決した:

$ sudo pip-2.7 install --upgrade selenium
Downloading/unpacking selenium
  Downloading selenium-2.25.0.tar.gz (2.0Mb): 2.0Mb downloaded
  Running setup.py egg_info for package selenium
    
    warning: no files found matching 'docs/api/py/index.rst'
Installing collected packages: selenium
  Found existing installation: selenium 2.21.2
    Uninstalling selenium:
      Successfully uninstalled selenium
  Running setup.py install for selenium
    
    warning: no files found matching 'docs/api/py/index.rst'
Successfully installed selenium
Cleaning up...

Windows + Python 2.7

since 2013-12-04

pip は入れてある:

>pip install selenium
Downloading/unpacking selenium
  Downloading selenium-2.37.2.tar.gz (2.6MB): 2.6MB downloaded
  Running setup.py egg_info for package selenium

Installing collected packages: selenium
  Running setup.py install for selenium

Successfully installed selenium
Cleaning up...

参考 http://d.hatena.ne.jp/x736b/20120909/1347180911

NVDAとSelenium

since 2014-01-24

下記のようなことを NVDA と一緒に実行すると Tab 移動は動くがクイックナビゲーション (2, Shift+2) は動かない。

クイックナビゲーションを実行するには Firefox ではなく NVDA にコマンドを送らなくてはならないのだろう。。

#!/usr/bin/env python2.7
# coding: utf-8
from __future__ import unicode_literals
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
 
baseUrl = 'http://www.nvda.jp'
driver = webdriver.Firefox()
driver.get(baseUrl + '/index.html')
assert "NVDA日本語版 ダウンロードと説明" in driver.title
 
ActionChains(driver).send_keys(Keys.TAB).perform()
time.sleep(5)
 
ActionChains(driver).send_keys('2').perform()
time.sleep(5)
 
ActionChains(driver).key_down(Keys.SHIFT).send_keys('2').key_up(Keys.SHIFT).perform()
time.sleep(5)
 
driver.close()
selenium.txt · 最終更新: 2014/01/24 16:11 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0