selenium.common.exceptions.WebDriverException:消息:无法连接到服务 /usr/bin/safaridriver

joh*_*ohn 2 python safari macos selenium selenium-webdriver

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

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

Run Code Online (Sandbox Code Playgroud)

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

Jac*_*Lee 5

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

webdriver.Safari(executable_path='/usr/bin/safaridriver')
Run Code Online (Sandbox Code Playgroud)