- Install relevant APT packages:
$ sudo apt-get install xorg $ sudo apt-get install xfvd $ sudo apt-get install firefox $ sudo apt-get install openjdk-7-jre $ sudo apt-get install python-pip
- Download Selenium server and Python bindings:
$ sudo pip install selenium $ wget https://selenium.googlecode.com/files/selenium-server-standalone-2.34.0.jar
- Start virtual framebuffer X server for server number 1 (for DISPLAY) in the background:
$ sudo Xvfb :1 & $ sudo Xvfb :1 -screen 0 1280x1024x8
- Start Selenium server in the background (without sudo):
$ java -jar selenium-server-standalone-2.34.0.jar &
- Write sample Python code in sample.py:
from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.send_keys("selenium") elem.send_keys(Keys.RETURN) assert "Google" in driver.title driver.close()
- Run sample.py with environment variable DISPLAY=:1:
$ DISPLAY=:1 python sample.py
ppt.cc/fVjECx ppt.cc/fEnHsx ppt.cc/fRZTnx ppt.cc/fSZ3cx ppt.cc/fLOuCx ppt.cc/fE9Nux ppt.cc/fL5Kyx ppt.cc/fIr1ax ppt.cc/f71Yqx tecmint.com linuxcool.com linux.die.net linux.it.net.cn ostechnix.com unix.com ubuntugeek.com runoob.com man.linuxde.net bit.ly/2EzoUDo bit.ly/2tW6eYT bit.ly/2X6vadl bit.ly/2viLpHU linuxprobe.com linuxtechi.com howtoforge.com linuxstory.org systutorials.com ghacks.net linuxopsys.com v.gd/2P9wTx v.gd/FtfpqE v.gd/eMfHsm v.gd/Ub7mqv v.gd/RReVk0 v.gd/vS3uTI v.gd/4Zxmba
Total Pageviews
Wednesday, 15 November 2017
Setting up Selenium Python environment with X virtual framebuffer on Ubuntu server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment