Oct 15, 2012

How to run Selenium in background in virtual display (Xvfb)

http://en.wikipedia.org/wiki/Xvfb

In the X Window System, Xvfb or X virtual framebuffer is an X11 server that performs all graphical operations in memory, not showing any screen output. From the point of view of the client, it acts exactly like any other server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to even have a screen or any input device. Only a network layer is necessary.

Xvfb is primarily used for testing

PyVirtualDisplay - a Python wrapper for Xvfb:
#!/usr/bin/env python

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

# now Firefox will run in a virtual display. 
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()

display.stop()
http://stackoverflow.com/questions/6183276/how-do-i-run-selenium-in-xvfb

No comments: