首页 > 解决方案 > selenium.common.exceptions.WebDriverException:消息:无法连接到服务 /usr/bin/safaridriver

问题描述

基本上,在我的 Mac 上,硒不起作用。我的代码是这样的:

from selenium import webdriver
webdriver.Safari('/usr/bin/safaridriver')

这实际上是最基本的 selenium 脚本,但它不起作用......在我的程序运行 30 秒后,我收到此错误:selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/bin/safaridriver. 我不知道为什么会这样……我的 safari 版本是最新的,(14.0.1),但我一直收到这个错误。谢谢你的帮助!

标签: pythonmacosseleniumselenium-webdriversafari

解决方案


传递给的第一个位置参数webdriver.Safari不是executable_path参数,而是port参数。您必须将路径作为位置参数传递。

webdriver.Safari(executable_path='/usr/bin/safaridriver')

推荐阅读