Error while launching safari browser using selenium webdriver--python

Hello Guys,


I am getting below error when tried to launch Safari browser using Selenium Webdriver with Python code. I don't have admin rights on my Mac.


Traceback (most recent call last):

File "BraveTest.py", line 45, in <module>

driver = webdriver.Safari(executable_path = safari_driverpath)

File "/Users/p785756/Library/Python/3.6/lib/python/site-packages/selenium/webdriver/safari/webdriver.py", line 57, in __init__

self.service.start()

File "/Users/p785756/Library/Python/3.6/lib/python/site-packages/selenium/webdriver/common/service.py", line 98, in start

self.assert_process_still_running()

File "/Users/p785756/Library/Python/3.6/lib/python/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running

% (self.path, return_code)

selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1


Code:


from selenium import webdriver


driver = webdriver.Safari()


As per the below instruction mentioned in the page @ https://webkit.org/blog/6900/webdriver-support-in-safari-10/


“Authorize safaridriver to launch the webdriverd service which hosts the local web server. To permit this, run /usr/bin/safaridriver once manually and complete the authentication prompt.”


I ran the command “/usr/bin/safaridriver –enable” in the mac terminal and it asked for the password. I have entered my user password but got the message saying password is not valid. Does it require Admin Password.


Pls help me resolve this issue.


Thanks in Advance.

Replies

hello Guys


I have the similar problem. The different is that I have admin rigths but when i want acces to Safari WebDriver (/usr/bin/safaridriver) the system report to me the next trace:


File "test.py", line 2, in <module>

driver = webdriver.Safari( port=0, executable_path="/usr/bin/safaridriver", quiet=False)

File "/Users/yatt/.virtualenvs/3320/lib/python3.7/site-packages/selenium/webdriver/safari/webdriver.py", line 57, in __init__

self.service.start()

File "/Users/yatt/.virtualenvs/3320/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 98, in start

self.assert_process_still_running()

File "/Users/yatt/.virtualenvs/3320/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running

% (self.path, return_code)

selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1


The code is the next that I use is the next:



from selenium import webdriver


driver = webdriver.Safari( port=0, executable_path="/usr/bin/safaridriver", quiet=False)


If i habilitated the enable automotation in safari browser where would be the problem?


Please Help me¡


Thanks.

Hello pradeep859,

It is required that you authenticate with an administrator account when running safaridriver --enable. It sounds like your account is a normal user account, which won't work. You'll need to arrange administrator access with whomever manages your machine.

Thanks, BJ
Dear daniel.camacho,

I don't know enough about your situation to debug the issue. Are you able to launch /usr/bin/safaridriver -p <port> successfully outside of using Selenium (i.e., from Terminal.app window)? If so, I'd recommend you get in touch with the Selenium community to figure out why your Selenium script is not behaving as expected. You can learn more about Selenium on their homepage, which is easily found with a web search.

Thanks, BJ


This is perhaps a bit late but I ran into the same issue, what worked for me was to specify the parameter as following:
driver = webdriver.Safari(executable_path='/usr/bin/safaridriver')

check original answer in github: https://github.com/SeleniumHQ/selenium/issues/5109

Hopes this helps anyone running in to this issue in the future!
You need administrator privileges, or to be added to the _webdeveloper user group to run safaridriver --enable.

If you don't have administrator privileges, but you do belong to the _webdeveloper group, you need to enter the administrator password when you run safari driver --enable. You will get an error message Password is not valid, please try again., but the server (now called webinspectord in Ventura 13.2.1) starts properly and you can use Selenium.