selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions while using GeckoDriver

天涯浪子 提交于 2019-12-11 15:57:38

问题


I've had some trouble trying to get selenium to do stuff with browsers. I'm a super-beginner at this type of stuff, but I still searched, and the most pertinent response I found was that I needed to run the Application as administrator, but it didn't change anything. Here's my code and the error message. Thanks alot.

import time
from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")

My error message :

Traceback (most recent call last):
  File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Axel\Desktop\PYTHON\code.py", line 3, in <module>
    driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")
  File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
    self.service.start()
  File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions. 

I'm pretty sure these two errors are just one, and I've gone through a whole bunch of threads, but i never properly understand things. I wondered if it had something to do with geckdriver (which i havem't and don't know how to install.) Thanks alot!


回答1:


This error message...

selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions.

...implies that the Mozilla Firefox executable was unaccessable due to wrong permissions.

While working with Selenium v3.x, GeckoDriver and Firefox you have to consider certain facts as follows:

  • Instead of Mozilla Firefox binary (i.e. firefox.exe) you need to pass the absolute path of the GeckoDriver binary through the argument executable_path within single quotes (i.e. '') along with the raw (r) switch.
  • You need to download the latest release of GeckoDriver from this link and ensure that GeckoDriver have required permissions to be accessed by non-root user.
  • Always execute your TestCases/TestSuite as a non-root user.
  • Your effective code block will be as follows:

    from selenium import webdriver
    driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
    



回答2:


I believe that for Firefox version (47.0 +) you need to use geckodriver. Check it out here: https://github.com/mozilla/geckodriver/releases



来源:https://stackoverflow.com/questions/50767308/selenium-common-exceptions-webdriverexception-message-mozilla-firefox-execut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!