使用
启动浏览器后,Safari浏览器会立即关闭java.util.concurrent.ExecutionException:org.openqa.selenium.WebDriverException:java.lang.reflect.InvocationTargetException
这是我的环视详情 硒2.46。 Mac OS X 10.10.3 x86_64 Safari 8.0.5
这是我的示例python代码
from selenium import webdriver
def test():
driver = webdriver.Safari()
driver.get("www.google.com")
当我运行上述功能时,我得到以下输出
15:57:46.465 INFO - Launching a standalone Selenium Server
15:57:46.491 INFO - Java: Oracle Corporation 24.45-b08
15:57:46.491 INFO - OS: Mac OS X 10.10.3 x86_64
15:57:46.500 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
15:57:46.551 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform MAC
15:57:46.552 INFO - Driver class not found: com.opera.core.systems.OperaDriver
15:57:46.552 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
15:57:46.603 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:50220/wd/hub
15:57:46.603 INFO - Selenium Server is up and running
15:57:56.500 INFO - Executing: [new session: Capabilities [{platform=ANY, javascriptEnabled=true, browserName=safari, version=}]])
15:57:56.508 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=safari, version=}]
15:57:56.561 INFO - Server started on port 39602
15:57:56.570 INFO - Launching Safari
15:57:56.579 INFO - Waiting for SafariDriver to connect
15:57:58.044 INFO - Connection opened
15:57:58.046 INFO - Driver connected in 1466 ms
15:57:58.071 INFO - Shutting down
15:57:58.071 INFO - Closing connection
15:57:58.072 INFO - Stopping Safari
15:57:58.123 INFO - Stopping server
15:57:58.124 INFO - Stopping server
15:57:58.132 INFO - Shutdown complete
15:57:58.134 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'L502062.local', ip: '10.10.80.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_45'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:137)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:58)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:174)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:202)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:164)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'L502062.local', ip: '10.10.80.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_45'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:95)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:79)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:62)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:85)
... 9 more
Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'L502062.local', ip: '10.10.80.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_45'
Driver info: driver.version: SafariDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:51)
... 14 more
Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
... 19 more
15:57:58.139 WARN - Exception: com.google.gson.JsonObject cannot be cast to java.lang.String
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: Cannot access execution context
Traceback (most recent call last):
File "/Users/veeraa/Documents/workspace/med_selenium/lib/ui/safari_test.py", line 30, in <module>
MyClass().test()
File "<string>", line 2, in test
File "/Library/Python/2.7/site-packages/Selenium2Library/keywords/keywordgroup.py", line 15, in _run_on_failure_decorator
return method(*args, **kwargs)
File "/Users/veeraa/Documents/workspace/med_selenium/lib/ui/safari_test.py", line 26, in test
self.driver = webdriver.Safari()
File "/Library/Python/2.7/site-packages/selenium/webdriver/safari/webdriver.py", line 62, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 89, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 138, in start_session
'desiredCapabilities': desired_capabilities,
File "/Library/Python/2.7/site-packages/Selenium2Library/webdrivermonkeypatches.py", line 11, in execute
result = self._base_execute(driver_command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 195, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 170, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: com.google.gson.JsonObject cannot be cast to java.lang.String
Stacktrace:
at org.openqa.selenium.remote.JsonToBeanConverter.convert (JsonToBeanConverter.java:111)
at org.openqa.selenium.remote.JsonToBeanConverter.convert (JsonToBeanConverter.java:42)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute (SafariDriverCommandExecutor.java:191)
at org.openqa.selenium.remote.RemoteWebDriver.execute (RemoteWebDriver.java:578)
at org.openqa.selenium.remote.RemoteWebDriver.startSession (RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.<init> (RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init> (RemoteWebDriver.java:141)
at org.openqa.selenium.safari.SafariDriver.<init> (SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.<init> (SafariDriver.java:51)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:526)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor (DefaultDriverProvider.java:85)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance (DefaultDriverProvider.java:79)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance (DefaultDriverFactory.java:62)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:1)
at java.util.concurrent.FutureTask.run (FutureTask.java:262)
at org.openqa.selenium.remote.server.DefaultSession$1.run (DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
at java.lang.Thread.run (Thread.java:744)
感谢是否有人可以帮我解决此问题?
非常感谢
答案 0 :(得分:1)
2.46不支持Safari驱动程序版本。尝试降级Selenium版本:
pip uninstall selenium
pip install -Iv selenium==2.45 or pip install selenium==2.45
答案 1 :(得分:1)
不确定这是否是同一个问题,但我刚刚在这里发布了一个可能有帮助的答案:Unable to run tests on Safari - Do we need dev certificate