Why is selenium webdriver Firefox not working for unprivileged users?

I am trying to use selenium to take screenshots in a Django view in python. Selenium firefox webdriver works well if I start it as root. However, when I try to start it with a non-superuser, it hangs when I try to instantiate the driver. Django is called through the apache user www-data

, so it suffers from this problem.

Is there a way to make the selenium firefox webdriver run as non-root?

From a fresh install of Ubuntu 14.04 I did the following

sudo apt-get install python-pip firefox xvfb
pip install selenium pyvirtualdisplay
useradd testuser

      

And then in the python shell:

from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
driver.get("http://askubuntu.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

      

If I login to python as root it works fine, if I use the testuser account the line driver = webdriver.Firefox()

has no response or errors.

I would be grateful for any suggestions on why this is happening.

+3


source to share


1 answer


I had the same problem with Selenium + Firefox on linux. The problem was that linux user: To run these tests Firefox must be able to create a profile (Firefox profile). This profile is inuser_home/.mozilla/firefox/profiles

So, in your case, make sure that:



  • This linux user can write in his own home.
  • In etc/passwd

    make sure that this user has a default shell, /bin/bash

    on the example of
  • In the directory where your webapp is located: try $ ls -larth

    : if all files in this are owned root

    , you can try to change the permissions in that folder to allow non-root users to access it (and then allowed to run Firefox + Selenium). You can also change the group permissions and add root and non-root users to this group.
0


source







All Articles