Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium Webdriver `Failed to start browser: Permission Denied`

I want to run a firefox webdriver with selenium so that I can spare a login with requests in a web crawler. I got the idea from this stackoverflow solution link, since the login with requests does not work for several reasons. I always get an error that the browser can't be started because the permission was denied. Here is my code:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary=FirefoxBinary("/path/to/firefox")
fp=webdriver.FirefoxProfile("path/to/extra/profile")


url="www.python.org"
driver = webdriver.Firefox(fp,  firefox_binary=binary, executable_path="path/to/geckodriver.exe")
driver.get(url)

The error is the following:

selenium.common.exceptions.WebDriverException: Message: Failed to start browser:
permission denied

Can anyone please help? I have been searching for years on the internet but can't find anything... Thanks!!!

like image 506
Tessa Avatar asked Oct 20 '16 14:10

Tessa


3 Answers

I'm trying to get Selenium 3 working for Firefox and was running into one error msg after another. After downloading geckodriver and adding it to the system path, this last error was the same permission denied issue you are seeing. After quite a bit of searching around and piecing things together, what finally worked was adding the firefox.exe to the path as well.

Here's the full script:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)

driver.get('http://www.google.com')

Hope this will work for you too.

like image 67
yyeo Avatar answered Oct 20 '22 04:10

yyeo


On Mac OS X, you need to point to the actual Firefox bin rather than just Firefox.app. At least that worked for me.

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/Users/YOUR_USERNAME/Applications/Firefox.app/Contents/MacOS/firefox-bin')
driver = webdriver.Firefox(firefox_binary=binary)
like image 3
Ben Wilson Avatar answered Oct 20 '22 05:10

Ben Wilson


Just use double back slash in the path on Windows:

binary = FirefoxBinary(r'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
like image 1
Aliaksei Plashchanski Avatar answered Oct 20 '22 04:10

Aliaksei Plashchanski