I have a python method that sets up the browser in headless mode on a linux server to cleanse a website using selenium. The display is fine-tuned, no matter which user runs the python script, but if the user sudodoes not execute the script, it will hang webdriver.Firefox()indefinitely on the installation line .
Here is the complete method:
def browserSetup(self, browser=None):
try:
self.display = Display(visible=0, size=(800, 600))
self.display.start()
if self.verbose:
print "Virtual display started for browser instantiation."
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1")
profile.set_preference("webdriver.log.file", "webdriver.log")
browser = webdriver.Firefox(profile)
if self.verbose:
print "Browser window object established @ %s." % browser
return browser
except Exception, e:
raise e
So, to repeat my problem: if the script is not executed as sudo, then the script will hang endlessly in the creation line webdriver.Firefox. Why is this happening?
UPDATE: the problem is this line:
browser = webdriver.Firefox()
Firefox , , - ; :
$ sudo Xvfb :10 -extension RANDR
[dix] Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi, removing from list!
[dix] Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
$ export DISPLAY=:10
$ firefox
(firefox:6347): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
//bin/dbus-launch terminated abnormally without any error message
...