python selenium webdriver safari driver

2019-04-11 19:31发布

问题:

Quick question, I've been building a python selenium framework for testing our site. I have successfully implemented Firefox, Chrome and IE for browser testing. But have been searching for Safari driver. I know in the official documents it briefly describes it's incompatibilities and doesn't support Safari. What would you guys suggest I use for testing Safari functionality with python and selenium. Is it possible using python?

I've searched and search and can't seem to find any related Safari driver.

Thanks in advance,

回答1:

Check out this blog post. It's for Java, but the process for Python ought to be much the same.



回答2:

The bindings for a local SafariDriver have not yet been implemented. If you want this feature, star the following issue at the bug tracker of Selenium:

  • Issue 5352: [SafariDriver] implement local safari driver in python binding


回答3:

I haven't used it myself, but there is a Safari driver available implemented as browser extension that injects javascript to each page.

It has some limitations such as not being able to handle alerts, but hopefully it helps.



回答4:

The Safari Driver is a Safari Extension you can find a link to on the downloads section of the seleniumhq.org site. http://docs.seleniumhq.org/download/

You can also check out the source from Github and build it.

The Python Selenium bindings for Safari are not really implemented,but use the java implementation. As a reaslt you need the Selenium-standalone-Server jar file. It must be in your PATH on the machine that runs the script.



回答5:

Python support is there to run Safari tests, you can find python example on this blog

another example how to invoke Safari tests over selenium grid, please note selenium grid and node should be running.

# -*- coding: utf-8 -*-
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

def setUp(self):
    self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities={'browserName':'safari','version':'safariversion','platform':'MAC'})

def test_search_in_python_org(self):
    driver = self.driver
    driver.get("http://www.python.org")
    self.assertIn("Python", driver.title)
    driver.maximize_window()
    elem = driver.find_element_by_name("q")
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    assert "No results found." not in driver.page_source


def tearDown(self):
    self.driver.quit()

if __name__ == "__main__":
    unittest.main()