Selenium错误 – 对远程WebDriver的HTTP请求在60秒后超时

我已经使用了几个月的Selenium,我们正在使用它来自动化我们的一些内部testingstream程。 脚本一直没有问题。 我最近使用FF 27.01升级到C#2.40.0 webdriver,我们的脚本现在在随机失败,出现以下错误。

[Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out [09:01:20] [Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e) at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition) at Portal.Test.Helpers.Process_Bookings.OpenBookings.SelectBooking(String bookingnumber) at Portal.SmokeTest.SmokeRunTest.Booking() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 68 --WebException at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) --TearDown at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.Close() at Portal.Test.Helpers.Setup.CloseWebdriver() at Portal.SmokeTest.SmokeRunTest.TearDown() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 162 --WebException at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 

我设法追踪到一行代码的最新错误:

 _setup.driver.FindElement(By.XPath("//button[@class='buttonSmall lockBookingButton']")).Click(); 

烦人的是,试图解决这个问题certificate是困难的,就好像我在我的本地机器上运行testing,在debugging它通过。 此外,如果我通过build立机器上的NUNIT跑步者运行它,我正在运行testing,它也通过。 在使用TeamCity时,它似乎只是我们的自动构build运行过程的一部分。 就像我说过的,这个在过去的几个月里一直运行良好,唯一改变的就是seleniumwebdriver套件。

我之前遇到过这个问题,而在debugging时,当一个Click()代码行被调用时,Firefox似乎locking了,只有停止testing才能让Firefox继续。 这里有一些build议,包括修改webdriver源代码? 如果有其他人可以提供任何build议,我想不要走这条路。

非常感谢您的意见。 🙂

 new FirefoxDriver(new FirefoxBinary(),new FirefoxProfile(),TimeSpan.FromSeconds(180)); 

使用上面的代码启动浏览器。 它为我工作。

几个月前我第一次遇到这个问题(也是在click()命令中),这对我来说一直是一个问题。 这似乎是.NET Selenium绑定的一些问题。 这个在IE驱动上工作的人的博客文章有助于解释发生了什么事情:

http://jimevansmusic.blogspot.com/2012/11/net-bindings-whaddaymean-no-response.html

不幸的是,似乎并没有真正的解决这个问题。 每当这个问题提出给selenium开发人员( 见这里 ),这是一个典型的回应 :

我们需要一个可重复的scheme,其中必须包括一个样本页面或链接到公共网站的页面,可以复制问题。

如果你能够提交一致的可重复的testing用例,那么这个bug可以很好的帮助你。

也就是说,也许你可以在此期间尝试这个解决方法。 如果您尝试click()的HTMLbuttonclick()具有包含Javascript的onclick属性,请考虑使用JavaScriptExecutor直接执行该代码,而不是调用click()命令。 我发现执行onclick Javascript直接允许我的一些testing通过。

使用Chrome驱动程序(v2.23)/运行TeamCity运行testing,我遇到了类似的问题。 我可以通过向Chrome选项添加“no-sandbox”标志来解决问题:

 var options = new ChromeOptions(); options.AddArgument("no-sandbox"); 

我不确定FF驱动程序是否有类似的选项。 据我所知,这个问题与TeamCity在SYSTEM帐户下运行Selenium有关。

在我的情况下,我的button的types是submitbutton ,我改变Click to Sumbit然后每一个工作很好。 像下面的东西,

driver.FindElement(By.Id("btnLogin")).Click();

driver.FindElement(By.Id("btnLogin")).Submit();

顺便说一句,我已经尝试了这个post中的所有答案,但不适合我。

我认为当您尝试访问您的Web驱动程序对象之后,会发生此问题

1)一个窗口已经closures,你还没有切换到父窗口

2)你切换到一个没有准备好的窗口,并且在你切换之后已经被更新了

等待windowhandles.count是你所期望的不考虑页面内容也不document.ready。 我仍然在寻找解决这个问题的方法

有类似的问题。 尝试设置更多的时间在驱动程序的构造函数 – 添加例如。

 var timespan = TimeSpan.FromMinutes(3); var driver = new FirefoxDriver(binary, profile, timeSpan); 

问题是你的构buildenv的Click()超时。你可能想挖掘Click()上发生的事情。

此外,尝试为Click()添加Retrys,因为根据networking速度等因素,评估需要更长的时间

在我的情况下,我发现这个错误发生在我们的团队build立服务器。 testing工作在我们的本地开发机器上。

问题是目标网站在生成服务器上configuration不正确,所以无法正确打开浏览器。

我们使用铬驱动程序,但我不确定这是否有所作为。