Python Selenium setting path to firefox profile (ubuntu)

firefoxpythonselenium

I have set the path to a newly created Firefox profile in Ubuntu OS using python & Selenium. But when I run the python script I am getting an error

OSError: [Errno 13] Permission denied

I have changed the permissions on the file to 755 and I am still getting the error and also tried sudo.

sudo chmod 775 /home/student/.mozilla/firefox/gwi6uqpe.Default\ User2/

This is the start of my python script:-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.by import By
import sys, time
import time

binary = FirefoxBinary('/home/student/.mozilla/firefox/gwi6uqpe.Default User2')
browser = webdriver.Firefox(firefox_binary=binary)

And this is the error message.

Traceback (most recent call last):

File "default2.py", line 9, in
browser = webdriver.Firefox(firefox_binary=binary)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 78, in init
self.binary, timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in init
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 67, in launch_browser
self._start_from_profile_path(self.profile.path)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 90, in _start_from_profile_path
env=self._firefox_env)
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied

How do I get around this, please.

Best Answer

On my machine, ~/.mozilla/firefox and it's subdirectories have user:usergroup 700 permissions. Is your script being executed by the student user? Otherwise, it will get permission denied. As an experiment, you could try giving .mozilla/firefox and .mozilla/firefox/profiles 766 permissions. I wouldn't run a production environment like that, but you could make a group with permissions and add your other user to that group.

EDIT: FirefoxBinary is not what to use for specifying a profile. Use FirefoxProfile instead:

profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default')
browser = webdriver.Firefox(firefox_profile=profile)
Related Topic