Created
November 27, 2012 00:09
-
-
Save cgoldberg/4151516 to your computer and use it in GitHub Desktop.
Headless Selenium WebDriver with xvfbwrapper
This file contains hidden or 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
#!/usr/bin/env python | |
from selenium import webdriver | |
from xvfbwrapper import Xvfb | |
# create a virtual display | |
vdisplay = Xvfb(width=1280, height=720) | |
vdisplay.start() | |
# do selenium stuff. look ma, no browser displayed! | |
browser = webdriver.Firefox() | |
browser.get('http://www.ubuntu.com') | |
assertIn('Ubuntu', browser.title) | |
# save a screenshot | |
browser.save_screenshot('screenie.png') | |
# quit browser instance | |
browser.quit() | |
# stop virtual display | |
vdisplay.stop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment