【问题标题】:selenium.common.exceptions.WebDriverException: Message: in Python selenium 4selenium.common.exceptions.WebDriverException:消息:在 Python selenium 4 中
【发布时间】:2022-01-21 22:19:48
【问题描述】:

以下代码在 python selenium 3.14 上运行没有问题:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(options=chrome_options)

但是在将 selenium 包从 3.14 升级到 4.1 之后,上面的代码不再工作了。完整的异常消息:

Traceback (most recent call last):
  File "selenium.py", line 8, in <module>
    browser = webdriver.Chrome(options=chrome_options)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 211, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: 

selenium.common.exceptions.WebDriverException: Message: 之后没有指定任何内容,我不知道出了什么问题。

chrome版本和chromedriver版本如下:

user@ubuntu:~/python$ google-chrome --version
Google Chrome 96.0.4664.110 

user@ubuntu:~/python$ chromedriver -v
ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@

任何帮助将不胜感激。

【问题讨论】:

    标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


    【解决方案1】:

    您可以尝试传递 chromedriver 二进制文件的绝对路径,如下所示:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    
    s = Service('/path/to/chromedriver')
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    browser = webdriver.Chrome(service=s, options=chrome_options)
    

    参考文献

    您可以在以下位置找到一些相关的详细讨论:

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2014-03-15
      • 2018-09-27
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 2017-02-21
      • 2019-06-13
      • 1970-01-01
      相关资源
      最近更新 更多