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
, 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.
source to share
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 in
So, in your case, make sure that:
- This linux user can write in his own home.
make sure that this user has a default shell,
on the example of
- In the directory where your webapp is located: try
$ ls -larth
: if all files in this are owned
, 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.
source to share