收到错误 selenium.common.exceptions.WebDriverException:消息:无法连接到服务

问题描述 投票:0回答:1

我是 selenium 新手,所以我尝试使用 python 打开 google.com 网页,但收到此错误。

raise WebDriverException(f"Can not connect to the Service {self._path}")
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /Users/Roseline/.cache/selenium/chromedriver/mac-x64/121.0.6167.85/chromedriver

这是我的代码

from selenium import webdriver

#keep chrome browser open after program finishes
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.google.com")

我预计会弹出一个窗口,告诉我无法授予权限,然后我必须进入我的系统首选项并进行身份验证并授予其权限。但是没有弹出,只有这个错误。

python macos google-chrome selenium-webdriver pycharm
1个回答
0
投票

无法使用您系统中的chrome浏览器。试试这个,对我有用。

#! /usr/bin/env python3


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

options = Options()
# options.headless = True
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options,service=Service(ChromeDriverManager().install()))

driver.get("https://www.google.com")
© www.soinside.com 2019 - 2024. All rights reserved.