首先,我要说的是,我已经看到这个问题发布了很多次,我已经阅读了大多数解决方案,但我仍然有问题。
我正在使用MacBook (10.15.6)和Safari (13.1.2)。我使用的是Youtube 2020.1.4,有一个为Python3.8编写的程序,使用selenium 3.14.1,它连接到PyCharm (实际上是任何网站-我也尝试过谷歌),并发送一个搜索词。我一直有的问题是Selenium无法连接到web驱动程序。
我遵循了上一篇文章中的步骤,允许从开发人员选项卡进行远程自动化,以及从终端屏幕手动执行safari驱动程序(safaridriver --enable)。
我也尝试过类似的Chrome示例连接代码,也得到了类似的错误。
下面是我正在运行的代码:
from selenium import webdriver
driver = webdriver.Safari()
driver.get('https://youtube.com')
searchbox = driver.find_element_by_xpath('//*[@id="search"]')
searchbox.send_keys('Paint Drying')
以下是Tracebacklog::
/Users/Fudgey/PycharmProjects/Web_Scrape/venv/bin/python /Users/Fudgey/PycharmProjects/Web_Scrape/web_auto_seln_v0.py
Traceback (most recent call last):
File "/Users/Fudgey/PycharmProjects/Web_Scrape/web_auto_seln_v0.py", line 3, in <module>
driver = webdriver.Safari()
File "/Users/Fudgey/PycharmProjects/Web_Scrape/venv/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py", line 56, in __init__
self.service.start()
File "/Users/Fudgey/PycharmProjects/Web_Scrape/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/bin/safaridriver
发布于 2020-09-17 17:27:17
要使用Safari,您需要选中浏览器的Allow automation remote选项,执行以下步骤:
1. Open Safari
2. Go to Safari > Preferences
3. Go to Advanced and in the bottom, there is an option "Show Develop menu in menu bar"
4. Check that option
5. Go to Develop
6. Check on "Allow Remote Automation"
7. Close/Quit the browser
现在您可以从您的代码安全地运行Safari了。
https://stackoverflow.com/questions/63927063
复制相似问题