Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium.common.exceptions.WebDriverException: Message: 'library' executable may have wrong permissions for ChromeDriver

I want to use the chrome webdriver to connect to "https://www.google.com". below is the code.

from selenium import webdriver  
import time  

driver = webdriver.Chrome("C:\\Users\\faisal\\library")  
driver.set_page_load_timeout(10)  
driver.get("https://www.google.com")  
driver.find_element_by_name("q").send_keys(" automation by name ")  
driver.find_element_by_name("blink").click()  
time.sleep(5)  
driver.close()  

When I run the test, the following error message is displayed.Its a permission problem

C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\Scripts\python.exe C:/Users/faisal/PycharmProjects/firstSeleniumTest2/test.py
Traceback (most recent call last):
  File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Python\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Python\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/faisal/PycharmProjects/firstSeleniumTest2/test.py", line 4, in <module>
    driver = webdriver.Chrome("C:\\Users\\faisal\\library")
  File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()
  File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\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: 'library' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home


Process finished with exit code 1
like image 736
faisal abdulai Avatar asked Apr 01 '18 03:04

faisal abdulai


3 Answers

The error says it all :

selenium.common.exceptions.WebDriverException: Message: 'library' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

In you code block you mentioned :

driver = webdriver.Chrome("C:\\Users\\faisal\\library")

The error clearly says your program was considering library as the ChromeDriver binary. Hence the error.

But as per the documentation of selenium.webdriver.chrome.webdriver the call to the WebDriver() is as :

class selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None)

So you need to change send the Key executable_path along with the Value as the absolute path within single qoute '' along with the raw (r) switch as follows :

driver = webdriver.Chrome(executable_path=r'C:\Users\faisal\library\chromedriver.exe')

Update

As per the counter question from @Mangohero1 of-coarse executable_path is optional but in case you provide only the absolute path as per the source code provided below the absolute path is considered as the Value to the Key executable_path.

class WebDriver(RemoteWebDriver):
    """
    Controls the ChromeDriver and allows you to drive the browser.

    You will need to download the ChromeDriver executable from
    http://chromedriver.storage.googleapis.com/index.html
    """

    def __init__(self, executable_path="chromedriver", port=0,
         options=None, service_args=None,
         desired_capabilities=None, service_log_path=None,
         chrome_options=None):
    """
    Creates a new instance of the chrome driver.

    Starts the service and then creates new instance of chrome driver.

    :Args:
     - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
like image 142
undetected Selenium Avatar answered Nov 20 '22 06:11

undetected Selenium


C:\Users\faisal\library is not the correct path to chromedriver. Give the actual path to your chromedriver file.

like image 35
Joseph Sible-Reinstate Monica Avatar answered Nov 20 '22 06:11

Joseph Sible-Reinstate Monica


In case of Linux providing permission will solve the problem.

Use

sudo chmod +x chromedriver
like image 2
Trect Avatar answered Nov 20 '22 05:11

Trect