macOS 上 selenium chrome webdriver 出现错误

macOS 上 selenium chrome webdriver 出现错误

我想在 Macos M2 上使用 selenium。我运行了以下代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")

我收到了这个错误:

WebDriverException                        Traceback (most recent call last)
/Users/alancuzon/Desktop/Scrap/scrap_sorare.ipynb Cellule 1 in <cell line: 8>()
      6 options = Options()
      7 options.add_argument("start-maximized")
----> 8 driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
      9 driver.get("https://www.google.com")

File ~/opt/miniconda3/envs/tensorflow/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py:69, in WebDriver.__init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
     66 if not service:
     67     service = Service(executable_path, port, service_args, service_log_path)
---> 69 super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
     70                  port, options,
     71                  service_args, desired_capabilities,
     72                  service_log_path, service, keep_alive)

File ~/opt/miniconda3/envs/tensorflow/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py:92, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
     89 self.service.start()
     91 try:
---> 92     super().__init__(
     93         command_executor=ChromiumRemoteConnection(
     94             remote_server_addr=self.service.service_url,
     95             browser_name=browser_name, vendor_prefix=vendor_prefix,
     96             keep_alive=keep_alive, ignore_proxy=_ignore_proxy),
     97         options=options)
     98 except Exception:
     99     self.quit()

File ~/opt/miniconda3/envs/tensorflow/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:270, in WebDriver.__init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    268 self._authenticator_id = None
    269 self.start_client()
--> 270 self.start_session(capabilities, browser_profile)

File ~/opt/miniconda3/envs/tensorflow/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:363, in WebDriver.start_session(self, capabilities, browser_profile)
    361 w3c_caps = _make_w3c_caps(capabilities)
    362 parameters = {"capabilities": w3c_caps}
--> 363 response = self.execute(Command.NEW_SESSION, parameters)
    364 if 'sessionId' not in response:
    365     response = response['value']

File ~/opt/miniconda3/envs/tensorflow/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:428, in WebDriver.execute(self, driver_command, params)
    426 response = self.command_executor.execute(driver_command, params)
    427 if response:
--> 428     self.error_handler.check_response(response)
    429     response['value'] = self._unwrap_value(
...
13  chromedriver                        0x0000000102574578 chromedriver + 3769720
14  chromedriver                        0x00000001025890f0 chromedriver + 3854576
15  libsystem_pthread.dylib             0x000000019287026c _pthread_start + 148
16  libsystem_pthread.dylib             0x000000019286b08c thread_start + 8

我下载了 chrome web driver,安装了 selenium 和 web driver manager。

你知道该如何进行吗?

多谢 !

答案1

我们正在使用 python 的 selenium 的 webdriver-manager 来管理我们的驱动程序,并且在这一行中遇到了同样的错误

driver = webdriver.Chrome(ChromeDriverManager().install())

为了解决这个问题,我们打开了 chrome 窗口 -> 设置 -> 关于 chrome -> 更新 chrome。或者在您的浏览器上输入 chrome://settings/help。

在完成新版本的 chrome 构建之后,同一行不再生成错误。

当然,这只有在谷歌推出了新版本的 Chrome 并修复了导致该问题的错误后才有效。

相关内容