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

一个人想着一个人 提交于 2021-02-04 05:55:33

问题


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

回答1:


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




回答2:


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



回答3:


In case of Linux providing permission will solve the problem.

Use

sudo chmod +x chromedriver



回答4:


driver=webdriver.Chrome("C:\\Users\\SQA Anas\\Downloads\\chromedriver.exe")

Please enter the complete chrome driver path like this: "C:\Users\SQA Anas\Downloads\chromedriver.exe"

Its works for me :)




回答5:


The executable_path should have chromedriver added at last:

executable_path='/home/selenium/Linkedin-Automation/chromedriver'



回答6:


I had to use the following to run on Windows 10 64 bit and 32 bit chromedriver:

driver = webdriver.Chrome(executable_path=r'C:\\Users\\My Name\\Downloads\\chromedriver_win32\\chromedriver.exe')


来源:https://stackoverflow.com/questions/49594492/selenium-common-exceptions-webdriverexception-message-library-executable-may

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