网络驱动程序间歇性地引发超时异常.对远程 Web 驱动程序服务器的 URL 的 HTTP 请求
本文关键字:驱动程序 Web 服务器 URL 请求 HTTP 异常 超时 网络 | 更新日期: 2023-09-27 18:37:21
从今天开始,我的测试开始在IE和Firefox上偶尔失败。所有的失败都给了我这个例外。今天早上我在VS2013
,Nunit 3.0.1
,IEDriver 2.45.0.0
,Selenium.Support
和Selenium.WebDriver
2.48.2。我认为这是因为我的软件包已过时并更新Selenium.Support
并Selenium.Webdriver
2.52.0
.例外继续间歇性地困扰着我的测试。唯一似乎与这些例外一致的是它们都是由
wait.Until(ExpectedConditions.someCondition(element));
OpenQA.Selenium.WebDriverException was unhandled by user code
HResult=-2146233088
Message=The HTTP request to the remote WebDriver server for URL http://localhost:7055/hub/session/e9b960bc-e750-41f1-93bf-7710bcfc1d5f/element timed out after 60 seconds.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)
at OpenQA.Selenium.By.<>c__DisplayClass1e.<CssSelector>b__1c(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
at POMAuctivaTest.AuctivaPageModels.BasePageModel.WaitForElementVisible(IWebDriver driver, By element) in c:'Users'jburns'Documents'Visual Studio 2013'Projects'POMAuctivaTest'POMAuctivaTest.AuctivaPageModels'BasePageModel.cs:line 125
at POMAuctivaTest.AuctivaPageModels.ProfileManagmentPageModel.ChangeDateCreatedSortMostRecent() in c:'Users'jburns'Documents'Visual Studio 2013'Projects'POMAuctivaTest'POMAuctivaTest.AuctivaPageModels'ProfileManagmentPageModel.cs:line 66
at POMAuctivaTest.TestSuite.ExistingUserTestSuite`1.CreateItemDetailProfileAndDelete() in c:'Users'jburns'Documents'Visual Studio 2013'Projects'POMAuctivaTest'POMAuctivaTest.TestSuite'ExistingUserTestSuite.cs:line 591
InnerException: System.Net.WebException
HResult=-2146233079
Message=The operation has timed out
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
InnerException:
任何帮助都会很棒 我对 webdriver 相对较新,并且对代码概念有初学者级别的了解,我很乐意提供额外的信息,这个问题已经让我倒退了一天,不能失去更多。帮我堆叠溢出你是我唯一的希望。
今天 3/7 我的测试没有像周四 (3/4) 那样遇到这个异常,今天早上当我的测试等待弹出窗口时,我遇到了一次。这是这条线 popupWindowHandle = finder.Click(NewListingPage.ImageSelectionPopupElement);
@PankajDubey 这是我所有等待方法的片段。我在这里使用显式等待吗?
public void WaitForElementVisible(IWebDriver driver, By element)
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
wait.Until(ExpectedConditions.ElementIsVisible(element));
}
catch (WebDriverTimeoutException)
{
TakeScreenshot(Driver);
Console.Write("Test failed trying to wait for this element " + element.ToString() + " to be visible ");
}
}
@Pankaj - 所以在我的OneTimeSetup
中,我按照建议将隐含的等待时间增加到 5 秒。当我运行测试时,他们未能找到屏幕上的元素。测试在ClickViewScheduled()
方法上反复失败。
ListingDonePage.WaitForElementVisible(Driver, ListerDonePageModel.ViewScheduledSelector);
var ScheduledListingPage = ListingDonePage.ClickViewScheduled();
这是ClickViewScheduled()
的定义。这对我来说很奇怪,因为在上一行中,它使用我在上面发布的等待方法等待元素的可见性。所以它"找到"了该行中的元素,然后找不到它进行点击?
public ScheduledListingsPageModel ClickViewScheduled()
{
ViewScheduledElement.Click();
return new ScheduledListingsPageModel(Driver);
}
使用隐式等待来处理此问题,其中您为每个方案声明了 Web 驱动程序实例而不是显式时间(等待语句)。
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
如果它不起作用,请输入您遇到此异常的代码片段以获取更多说明。