I’m trying to use Python’s Selenium bindings to programmatically interact with websites, as part of a Django website.
As my Selenium code runs as part of a Django website, by default (if I understand correctly) there is no display available for the browser to use. I’m thus trying to use PyVirtualDisplay to start Xvfb before my Selenium code runs.
Here‘s my code:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=False, size=(800, 600))
display.start()
browser = webdriver.Firefox()
When I SSH into my server (running Debian Squeeze, Python 2.6.6, Selenium 2.25, PyVirtualDisplay 0.1.0), run the Python console as myself, and type in the code above, it works fine.
However, when I try to run that code from my Django site, or use su
to run the Python console as www-data
(which I believe is the user that Django runs as), I get the following error:
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was:
(process:2963): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.
Xlib: extension "RANDR" missing on display ":1082.0".
(firefox-bin:2963): libgnomevfs-WARNING **: Unable to create ~/.gnome2 directory: Permission denied
Could not create per-user gnome configuration directory `/var/www/.gnome2/\': Permission denied'
I’m a bit of a noob with Xvfb and Linux, so I’m not quite sure what I’m doing wrong.