selenium.common.exceptions.WebDriverException:消息:'library' 可执行文件对 ChromeDriver 的权限可能有误

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

我想使用 chrome 网络驱动程序连接到“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()  

我在运行测试的时候,下面的错误信息是displayed.Its一个权限问题

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

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

错误说明了一切:

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

错误清楚地表明您的程序正在考虑将 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)

所以你需要更改发送 Key executable_path 以及 Value 作为单个 qoute '' 连同原始 (r) 开关如下:

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

更新

根据@Mangohero1 的反问 of-coarse executable_path 是可选的,但如果您根据提供的源代码仅提供 绝对路径 绝对路径下方被视为ValueKeyexecutable_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

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

请像这样输入完整的 chrome 驱动程序路径: "C:\Users\SQA Anas\Downloads\chromedriver.exe"

对我有用:)

如果Linux提供许可将解决问题。

使用

sudo chmod +x chromedriver

我不得不在 Windows 10 64 bit32 bit chromedriver 上对 运行 使用以下内容:

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

executable_path 最后应该添加了 chromedriver:

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