Anurag Pathak
Anurag Pathak

Reputation: 11

selenium setup with python for safari browser in mac

The am using selenium with Python in mac and facing problem to run the test cases in Safari browser.

The command sudo easy_install selenium prints the following in the terminal:

Searching for selenium Best match: selenium 3.5.0 Processing selenium-3.5.0-py2.7.egg selenium 3.5.0 is already the active version in easy-install.pth

Using /Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg Processing dependencies for selenium Finished processing dependencies for selenium

Now when I want to run a simple Python script to open a website, I use this code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Safari()
driver.get("https://www.google.co.in")

It shows this error in the terminal:

Traceback (most recent call last): File "a.py", line 5, in driver = webdriver.Safari() File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/safari/webdriver.py", line 52, in init desired_capabilities=desired_capabilities) File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 140, in init self.start_session(desired_capabilities, browser_profile) File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 229, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 297, in execute self.error_handler.check_response(response) File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Could not create a session: You must enable the 'Allow Remote Automation' option in Safari's Develop menu to control Safari via WebDriver

I am unable to find the exact problem.

Please help and thanks in advance.

Upvotes: 1

Views: 4121

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

Open Safari and the in Develop menu check the option for Allow Remote Execution

Enable Remote Automation

And also run safaridriver -p 5555 once in terminal, if it asks for allow permission then give it. This is only needed once. See the below article for more details

https://webkit.org/blog/6900/webdriver-support-in-safari-10/

Upvotes: 1

Related Questions