使用此网页
<html>
<title>My Test Page</title>
<input type="button" value="Authorize" class="standard" id="authButton">
<form action="http://google.com" target="_blank">
<input type="submit" value="Test Button">
</form>
</html>
我有以下测试脚本试图点击按钮,但没有在Safari中注册点击,它可以与Firefox和Chrome一起使用。运行OSX 10.10.3,python 2.7.9和Safari 8.
第一个按钮(授权)在单击时从不突出显示,当单击第二个按钮(测试按钮)时,永远不会启动新的网页。 (再次只能通过Safari失败,适用于Firefox和Chrome)
from selenium import webdriver
import unittest, time
import os
class Test(unittest.TestCase):
def setUp(self):
os.environ["SELENIUM_SERVER_JAR"] = "/Users/myhome/lib/selenium-server-standalone-2.45.0.jar"
self.driver = webdriver.Safari()
def test_(self):
driver = self.driver
driver.get("http://localhost/~myhome/test.html")
self.assertEqual("My Test Page", driver.title)
auth_button = driver.find_element_by_id("authButton")
auth_button.click()
auth_button = driver.find_element_by_css_selector("input[type=\"submit\"]")
auth_button.click()
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
我尝试使用睡眠语句无效,并且还使用javascript尝试了这些变体但没有成功:
driver.execute_script("document.getElementById('authButton').click();")
driver.execute_script("arguments[0].click();", auth_button)
控制台输出
.......
17:22:35.979 INFO - Server started on port 42249
17:22:35.999 INFO - Launching Safari
17:22:36.009 INFO - Waiting for SafariDriver to connect
17:22:38.386 INFO - Connection opened
17:22:38.388 INFO - Driver connected in 2379 ms
17:22:38.471 INFO - Done: [new session: Capabilities [{platform=ANY, javascriptEnabled=true, browserName=safari, version=}]]
17:22:38.487 INFO - Executing: [get: http://localhost/~lbieber/test.html])
17:22:38.564 INFO - Done: [get: http://localhost/~lbieber/test.html]
17:22:38.570 INFO - Executing: [get title])
17:22:38.675 INFO - Done: [get title]
17:22:38.681 INFO - Executing: [find element: By.id: authButton])
17:22:38.705 INFO - Done: [find element: By.id: authButton]
17:22:41.716 INFO - Executing: [click: 0 [[SafariDriver: safari on MAC (null)] -> id: authButton]])
17:22:41.729 INFO - Done: [click: 0 [[SafariDriver: safari on MAC (null)] -> id: authButton]]
17:22:41.734 INFO - Executing: [find element: By.cssSelector: input[type="submit"]])
17:22:41.739 INFO - Done: [find element: By.cssSelector: input[type="submit"]]
17:22:44.746 INFO - Executing: [click: 1 [[SafariDriver: safari on MAC (null)] -> css selector: input[type="submit"]]])
17:22:44.756 INFO - Done: [click: 1 [[SafariDriver: safari on MAC (null)] -> css selector: input[type="submit"]]]
17:22:49.767 INFO - Executing: [delete session: 447708df-40bc-4e3e-b797-4ef0d65037a5])
17:22:49.767 INFO - Shutting down
17:22:49.767 INFO - Closing connection
17:22:49.768 INFO - Stopping Safari
17:22:49.830 INFO - Stopping server
17:22:49.830 INFO - Stopping server
17:22:49.856 INFO - Shutdown complete
17:22:49.857 INFO - Done: [delete session: 447708df-40bc-4e3e-b797-4ef0d65037a5]
任何建议都将不胜感激。