Last active
April 8, 2018 02:21
-
-
Save cgoldberg/bef144f933ec3c736364 to your computer and use it in GitHub Desktop.
selenium-rum
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
""" | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added 10 sec pageload timeouts