Selenium webdriver.Firefox not starting for a user not using sudo

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:
        # now Firefox will run in a virtual display. you will not see the browser.  
        self.display = Display(visible=0, size=(800, 600))
        self.display.start()

        if self.verbose:
            print "Virtual display started for browser instantiation."

        #change user agent
        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")

        # Create a new instance of the Firefox driver
        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() #with or without the profile variable - the results are the same

Firefox , , - ; :

#initialize the virtual display
$ 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!

#now start firefox in another ssh window (since the Xvfb process is consuming my prompt)
$ 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

...

+4
3

Xvfb ( X-) .

, $ sudo Xvfb :1 & $ sudo Xvfb :1 -screen 0 1280x1024x8.

, script, DISPLAY.

, $ DISPLAY=:1 python your_script.py.

+1

, .

sudo Firefox . DISPLAY.

: - env_reset sudoers. - sudo -i, DISPLAY.

+2

, usr/lib , perms .

sudo chmod 755 /usr/lib

, . , , .

0

Source: https://habr.com/ru/post/1529117/


All Articles