Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Last active April 8, 2018 02:21
Show Gist options
  • Save cgoldberg/bef144f933ec3c736364 to your computer and use it in GitHub Desktop.
Save cgoldberg/bef144f933ec3c736364 to your computer and use it in GitHub Desktop.
selenium-rum
"""
Instructions
************
1. install ubuntu deps:
-----------------------
sudo apt-get python-pip
sudo apt-get install firefox
sudo apt-get install chromium-browser
sudo apt-get intall xvfb
2. install python deps:
-----------------------
sudo pip install selenium
sudo pip install xvfbwrapper
3. install chromedriver:
------------------------
wget -N http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv -f chromedriver /usr/local/bin/chromedriver
4. adjust URL in script below.
5. run the script!
"""
import time
from selenium import webdriver
from xvfbwrapper import Xvfb
URL = 'http://foo'
INTERVAL = 15
print 'starting xvfb for virtual display...\n'
with Xvfb() as xvfb:
while True:
for browser in ('Firefox', 'Chrome'):
browser_class = getattr(webdriver, browser)
print 'starting browser: %s' % browser
driver = browser_class()
driver.set_page_load_timeout(10)
print 'navigating to: %s' % URL
try:
driver.get(URL)
except Exception as e:
print e
print 'closing browser\n'
driver.quit()
time.sleep(INTERVAL)
@danriti
Copy link

danriti commented Dec 1, 2015

Had to install chromium-browser instead of chrome.

@cgoldberg
Copy link
Author

updated instructions to say chromium-driver.

@cgoldberg
Copy link
Author

added 10 sec pageload timeouts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment