Created
November 21, 2016 15:57
-
-
Save sogaoh/235cac1df3b9dfcb6b6df91f34251d23 to your computer and use it in GitHub Desktop.
[Selenium]スクリーンショット画像取得方法一例 ref: http://qiita.com/sogaoh/items/c5005f7c93a9d4b8e8c4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vagrant box add {title} {url} | |
$ vagrant init {title} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vagrant up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vi /etc/hostname //→ 自分の好きなホスト名に | |
# (ホストOS側でダウンロードした jdk-8u65-linux-x64.tar.gz をゲスト側に転送し /tmp/ に置いた) | |
# cd /tmp | |
# tar xvfz jdk-8u65-linux-x64.tar.gz | |
# mv jdk1.8.0_65 /opt/ | |
# cd /usr/local/bin | |
# sudo ln -s /opt/jdk1.8.0_65/bin/java java //→ /usr/local/bin/java | |
# java -version //→ java インストール確認 | |
# cd /tmp | |
# sudo aptitude install xvfb xserver-xephyr firefox firefox-locale-ja fonts-ipaexfont-gothic fonts-ipafont-gothic | |
# wget http://peak.telecommunity.com/dist/ez_setup.py (Python 2.7.6 が入ってるのを確認したうえで: python -V ) | |
# sudo python ez_setup.py | |
# sudo easy_install pip | |
# pip --version | |
# sudo pip install pyvirtualdisplay | |
# sudo pip install selenium | |
# wget http://selenium.googlecode.com/files/selenium-server-standalone-2.22.0.jar | |
# mv selenium-server-standalone-2.22.0.jar /opt/ //→ /opt/selenium-server-standalone-2.22.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cd /opt | |
# wget https://ftp.mozilla.org/pub/firefox/releases/46.0.1/linux-x86_64/ja/firefox-46.0.1.tar.bz2 | |
# tar jxf firefox-46.0.1.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo su - | |
ps -ef | grep selenium | |
(java のプロセス : seleniumのjar呼び出し がなければ未起動) | |
nohup java -jar /opt/selenium-server-standalone-2.22.0.jar & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python | |
>>> from pyvirtualdisplay import Display | |
>>> from selenium import webdriver | |
>>> from selenium.webdriver.firefox.firefox_binary import FirefoxBinary | |
>>> | |
>>> display = Display(visible=0, size=(800, 600)) | |
>>> display.start() | |
<Display cmd_param=['Xvfb', '-br', '-screen', '0', '800x600x24', ':1125'] alias={alias} cmd=['Xvfb', '-br', '-screen', '0', '800x600x24', ':1125'] ({scmd}) oserror=None returncode=None stdout="None" stderr="None" timeout=False> | |
>>> | |
>>> binary = FirefoxBinary('/opt/firefox/firefox') | |
>>> browser = webdriver.Firefox(firefox_binary=binary) | |
>>> browser.get('https://www.ann-kate.jp/') | |
>>> browser.save_screenshot('ann-kate.png') | |
True | |
>>> browser.quit() | |
>>> display.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment