16

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!!!

Joe
  • 879
  • 3
  • 14
  • 37
Tessa
  • 287
  • 3
  • 5
  • 14
  • Could you try just `driver = webdriver.Firefox()` without using `Profile`? Same problem? – Andersson Oct 20 '16 at 14:08
  • @Andersson Same Problem! – Tessa Oct 20 '16 at 14:38
  • simple solution could be download chromedriver: http://chromedriver.storage.googleapis.com/index.html?path=2.24/ unzip it and put in scripts folder of python and use driver = webdriver.Chrome()..I am saying this because your aim is to scrap the page & not testing the UI of Web App – thebadguy Oct 20 '16 at 14:39
  • @thebadguy Does the chromedriver also provide the opportunity to keep logged into a homepage, which is what I am trying to accomplish with the firefox profile? – Tessa Oct 20 '16 at 14:40
  • @Tessa..yes...hope this http://stackoverflow.com/a/31063104/2425654 will help you – thebadguy Oct 20 '16 at 14:45
  • @Tessa, you could change permissions to `"/path/to/firefox"` folder or reinstall `Firefox` into another folder that will not have limited permissions – Andersson Oct 20 '16 at 14:47
  • @Andersson How would I have to change the permissions? Sorry I am rather a newby... – Tessa Oct 20 '16 at 14:50
  • @Tessa, https://technet.microsoft.com/en-us/library/cc754344(v=ws.11).aspx (for `Windows 7`) – Andersson Oct 20 '16 at 14:55
  • @Andersson Doesn't help either! I tried new permissions and have Firefox now in a new full access directory... I guess I have to try with Chrome then... – Tessa Oct 20 '16 at 15:25

5 Answers5

12

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.

yyeo
  • 121
  • 4
  • 2
    Thanks this helped. I still received the error `Failed to start browser entitiy, not found. Webdriver firefox`. To fix this I had to update firefox. Then I got the error `WebDriverException: Message: Missing 'marionetteProtocol' field in handshake`. To fix this I changed the "f" to capital "F" in "firefox.exe" in the line `binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')` – Viragos Nov 10 '16 at 03:49
  • I still had the permission error after trying this solution. I tried Viragos's suggestion of changing the "firefox.exe" to "Firefox.exe" in the `FirefoxBinary()` constructor. Now I get another webdriver exception: "Socket timeout reading Marionette handshake data: An existing connection was forcibly closed by the remote host. (os error 10054)." – Jake Stevens-Haas Jul 15 '19 at 20:16
3

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)
Ben Wilson
  • 2,271
  • 3
  • 26
  • 35
1

Just use double back slash in the path on Windows:

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

On Windows 10 with Selenium 3.14.1, the below code worked for me.

binary = FirefoxBinary(r'C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, 
executable_path='C:\\Tools\\Selenium\\geckodriver.exe')
driver.get("https://www.python.org")

Hope this helps..

Sethu S
  • 89
  • 4
0

Update Firefox browser on your machine and download latest gecko driver. That worked for me well.