由于在当前版本的Safari和safaridriver中检测元素可见性的问题,如上所述here,我尝试使用Safari Technology Preview启动测试。电话在这里:
return new SafariDriver("/Applications/Safari Technology Preview.app/Contents/MacOS/");
这似乎有效,因为它在测试开始时启动了Safari Technology Preview。但是,在它启动后,没有任何反应,我收到以下内容:
Error: ConnectFailure (Connection refused)
完整的堆栈跟踪在这里:
1) Error : TESTNAME
OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:62221/session. The status of the exception was ReceiveFailure, and the message was: Error getting response stream (ReadDone2): ReceiveFailure
----> System.Net.WebException : Error getting response stream (ReadDone2): ReceiveFailure
----> System.Exception : at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.WebConnection.ReadDone (System.IAsyncResult result) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
TearDown : System.NullReferenceException : Object reference not set to an instance of an object
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse (System.Net.WebRequest request) [0x000ce] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute (OpenQA.Selenium.Remote.Command commandToExecute) [0x000bd] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute (OpenQA.Selenium.Remote.Command commandToExecute) [0x00038] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute (System.String driverCommandToExecute, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters) [0x00014] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession (OpenQA.Selenium.ICapabilities desiredCapabilities) [0x0001e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor (OpenQA.Selenium.Remote.ICommandExecutor commandExecutor, OpenQA.Selenium.ICapabilities desiredCapabilities) [0x0001e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (OpenQA.Selenium.Safari.SafariDriverService service, OpenQA.Selenium.Safari.SafariOptions options, System.TimeSpan commandTimeout) [0x0000e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory, OpenQA.Selenium.Safari.SafariOptions options, System.TimeSpan commandTimeout) [0x00007] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory, OpenQA.Selenium.Safari.SafariOptions options) [0x00000] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory) [0x00007] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at Core.Selenium.SafariDriverFactory.CreateDriver (Core.Selenium.BrowserProfileManager profileManager) [0x00001] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at Core.Selenium.DriverController.CreateWebDriver (Core.Enums.DriverType type) [0x00078] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at Core.Selenium.DriverController..ctor (Core.Enums.DriverType type, System.DateTime creationTime, System.Boolean useProfile) [0x00045] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <8f2c484307284b51944a1a13a14c0266>:0
--WebException
at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse (System.Net.WebRequest request) [0x00008] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
--Exception
at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00044] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
注意:如果我使用当前版本的Safari,我不会收到此错误。
我使用Selenium 3.0.1在dotnet中实现了代码。我正在使用Safari Technology Preview v.22,macOS Sierra 10.12.3。在“开发”菜单中选中“允许远程自动化”。我手动运行/ Applications / Safari Technology Preview.app/Contents/MacOS/safaridriver。
有关如何使其发挥作用的任何想法?
答案 0 :(得分:2)
在Python中,我就是这样做的:
driver = webdriver.Safari(port=0, executable_path="/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver")
driver.get("https://www.google.com")
您可能还想看一下: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/safari/SafariOptions.html
在这里:https://github.com/SeleniumHQ/selenium/issues/3506 lmtierney说:
这取决于您使用的语言绑定。您应该能够在某处传递可执行文件路径,它将是/ Applications / Safari Technology Preview / Contents / MacOS / safaridriver。某些语言绑定允许标志自动使用技术预览safaridriver。
我希望这会有所帮助。 :)