0

First let me say, I have seen this question posted many times before and I have read the majority of the solutions but I am still having issues.

I am using a MacBook (10.15.6) and Safari (13.1.2). I am using PyCharm 2020.1.4 and have a program written for python 3.8 using selenium 3.14.1, which connects to Youtube (any website really- I have tried Google as well) and sends a search term. The issue that I keep having is that Selenium cannot connect to the web driver.

I have followed the steps from previous posts to allow Remote Automation from the developer tab, as well as manually executing safari driver (safaridriver --enable) from the terminal screen.

I have tried similar sample connection code for Chrome as well, and get similar errors.

Here is the code that I am running:

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')   

Here is the 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
  • Try reading this link https://github.com/SeleniumHQ/selenium/issues/5109 – Ro0t Sep 16 '20 at 19:57
  • This link details the steps that I have already taken, but I am still getting the same issue. – user14289812 Sep 18 '20 at 13:33
  • Not sure if it helps, but I tried just a simple assignment for the Chrome driver andI get same exact error. Here is the code 'from selenium import webdriver driver = webdriver.Chrome()' – user14289812 Sep 18 '20 at 18:22

1 Answers1

0

In order to use Safari, you need to check the Allow automation remote option for the browser, to do that follow these steps:

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

Now you can run Safari safely from your code.

Alin Stelian
  • 861
  • 1
  • 6
  • 16
  • I have tried this, and it still will not connect to the WebDriver. I have tried running the code via PyCharm as well as IDLE, and lastly via python console itself. All give the same error. – user14289812 Sep 17 '20 at 19:47