Search code examples
python-3.xseleniumselenium-webdrivermozillageckodriver

SessionNotCreatedException: Message: permission denied while using geckodriver for Selenium using Python (in Windows 10)


I've downloaded the latest version of Firefox and corresponding (64 bit) geckodriver. Added the location of the geckodriver executable to PATH. Yet, when I execute the following code:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')

to call Firefox, I get the following error:

Traceback (most recent call last):
  File "C:\Users\Karun\Documents\NJCC all data at once Selenium.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\Karun\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 162, in __init__
    keep_alive=True)
  File "C:\Users\Karun\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Users\Karun\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Karun\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Karun\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: permission denied

Solution

  • The error you are seeing does gives us a hint about what could have gone wrong as follows :

    Traceback (most recent call last):
      File "C:\Users\Karun\Documents\NJCC all data at once Selenium.py", line 2, in <module>
        browser = webdriver.Firefox()
    selenium.common.exceptions.SessionNotCreatedException: Message: permission denied
    

    Though you mentioned that you have added the location of the geckodriver executable to PATH but still facing the above mentioned error, so a simple solution will be to download the latest GeckoDriver from mozilla/geckodriver and pass the Key executable_path along with the Value of the absolute path of the GeckoDriver binary while initializing the webdriver and Web Browser instance as follows :

    from selenium import webdriver
    
    driver=webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
    driver.get("http://www.google.com")
    print("Page Title is : %s" %driver.title)
    driver.quit()
    

    Additionally ensure that you are using :

    • The latest JDK version i.e. Java SE Development Kit 8u161
    • The latest Selenium Python Client i.e. Selenium 3.9.0
    • The latest GeckoDriver i.e. GeckoDriver v0.19.1
    • The latest Firefox version i.e. Firefox Quantum v58.0.2
    • Clean the Project Space from your IDE before and after your Tests.
    • Run CCleaner tool to wipe off the OS chores before and after executing your Test Suite.
    • If the base version of Firefox is too old uninstall Firefox through Revo Uninstaller and install a recent GA released version of Firefox.
    • Execute your Tests.