selenium.common.exceptions.WebDriverException:消息:“库”可执行文件可能具有错误的 ChromeDriver 权限

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

提问人:faisal abdulai 提问时间:4/1/2018 最后编辑:undetected Seleniumfaisal abdulai 更新时间:12/29/2020 访问量:22452

问:

我想使用 chrome webdriver 连接到“https://www.google.com”。 下面是代码。

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()  

运行测试时,显示以下错误消息。这是一个权限问题

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
python selenium selenium-webdriver selenium-chromedriver chrome-web-driver

评论


答:

4赞 Joseph Sible-Reinstate Monica 4/1/2018 #1

C:\Users\faisal\library不是通往 Chromederiver 的正确路径。提供 chromedriver 文件的实际路径。

评论

3赞 faisal abdulai 4/1/2018
实际路径是:“C:\\Users\\faisal\\library\\chromedriver.exe”谢谢
9赞 undetected Selenium 4/1/2018 #2

错误说明了一切:

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

在您的代码块中,您提到了:

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

该错误清楚地表明您的程序正在考虑将库作为 ChromeDriver 二进制文件。因此错误。

但根据 selenium.webdriver.chrome.webdriver 的文档,对 的调用如下:WebDriver()

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)

因此,您需要将 KeyValue 一起更改为单个 qoute 中的绝对路径以及原始开关,如下所示:executable_path''(r)

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

更新

根据 @Mangohero1 的反驳问题,粗略是可选的,但如果您仅提供绝对路径,则根据下面提供的源代码,绝对路径被视为executable_pathexecutable_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

评论

1赞 Mangohero1 4/1/2018
实际上,如果我没记错的话,显式设置密钥是可选的。但是,是的,它必须是绝对的道路。executable_path
0赞 undetected Selenium 4/1/2018
@Mangohero1 谢谢,根据您的反问添加了更新。如果有任何进一步的疑问,请告诉我。
0赞 Muhammad Anas 3/12/2019 #3

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

请输入完整的 chrome 驱动程序路径,如下所示: “C:\Users\SQA Anas\Downloads\chromedriver.exe”

它对我有用:)

2赞 Trect 7/24/2019 #4

在Linux的情况下,提供权限将解决问题。

sudo chmod +x chromedriver
0赞 user8735309 5/18/2020 #5

我不得不使用以下内容来运行:Windows 1064 bit32 bit chromedriver

driver = webdriver.Chrome(executable_path=r'C:\\Users\\My Name\\Downloads\\chromedriver_win32\\chromedriver.exe')
0赞 vaidehi joshi 12/29/2020 #6

executable_path最后应该添加 chromedriver:

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