Unable to start Selenium Safari WebDriver via python3

一世执手 提交于 2019-12-11 00:08:14

问题


I want to use Safari as the browser from python, and the code is fairly easy:

from selenium import webdriver
driver = webdriver.Safari()
url = 'https://www.gmail.com/'
driver.get(url)

I am using the latest version of Safari, 11.0.3,

In preferences-extension, I have WebDriver installed,

In develop on menu, I have "allow Remote Automation" enabled.

I'm using python 3.5, selenium 3.10.0

While running the code above, I got the following Error message:

Traceback (most recent call last):
  File "/Users/hwang/Documents/Lumi_personal/Coding/sandbox/testSelenium.py", line 2, in <module>
driver = webdriver.Safari()

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/safari/webdriver.py", line 49, in __init__
self.service.start()

AttributeError: 'WebDriver' object has no attribute 'service'

Any help is appreciated! Thanks in advance!


回答1:


I had the same issue with selenium 3.10, but not with 3.9.

Apparently, there's a bug in version 3.10 according to: https://github.com/SeleniumHQ/selenium/issues/5578

My temporary solution is to uninstall selenium 3.10, and install 3.9:

pip uninstall selenium
pip install selenium==3.9

And it should solve the problem.




回答2:


You can also "patch" Safari webdriver by adding line 25 and 49 https://github.com/SeleniumHQ/selenium/commit/2a0f63d19bd6e666ad432ee459762489d6b6033a




回答3:


You need to pass the argument executable_path along with the absolute path of the safaridriver binary as follows :

from selenium import webdriver

driver = webdriver.Safari(executable_path='/path/to/safaridriver')
driver.get('https://www.google.co.in')


来源:https://stackoverflow.com/questions/49158246/unable-to-start-selenium-safari-webdriver-via-python3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!