我最近从3.9.1升级到Selenium 3.14。现在我每次运行时都会遇到错误,我尝试实例化webdriver。下面是它失败的行并抛出一个expecption。
当我降级到3.9.1时它工作正常。有什么我想念的吗?有没有人看过这个?
我正在使用c#+ Spec flow + BrowserStack网格。
如果您需要更多信息,请与我们联系。这是我的第一篇文章,并进行了Google搜索和研究,但无法找到有关此错误的任何信息。
_driver = new RemoteWebDriver(new Uri("http://" + browserStackConfig["BSserver"] + "/wd/hub/"), capability, new TimeSpan(0,0,30));
Result Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://hub-cloud.browserstack.com/wd/hub/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.
----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host
Selenium在7月25日做了一个更改,以从HttpCommandExecutor类公开Proxy属性(下面是链接)。您可能希望如果没有传递代理,那么Selenium将使用默认Web代理。不是这种情况。代理被设置为null,这将导致执行程序在实例化驱动程序时失败。
修复:我在代码中进行了简单的更改以传递默认的Web代理。以下是代码段。这解决了我的问题。
var executor = new HttpCommandExecutor(new Uri("http://" + browserStackConfig["BSserver"] + "/wd/hub/"), new TimeSpan(0, 0, 0, 30));
executor.Proxy = WebRequest.DefaultWebProxy;
_driver = new RemoteWebDriver(executor, capability);