【发布时间】:2014-09-30 19:34:24
【问题描述】:
我一直在 Chrome 中开发 Selenium 网络驱动程序,无法设置默认页面加载等待时间。测试速度较慢的网页时,驱动程序会在 60 秒后超时。
我尝试了两种方法:
1:
TimeSpan PageLoad = new TimeSpan(0, 0, 120);
driver = new ChromeDriver(ChromeDriverPath);
driver.Manage().Timeouts().SetPageLoadTimeout(PageLoad);
和
2:
public static void WaitForPageLoading()
{
WebDriverWait wait = new WebDriverWait(iwdCurrentlyUsedDriver, TimeSpan.FromSeconds(120));
wait.Until<bool>((d) =>
{
try
{
string test = ((OpenQA.Selenium.IJavaScriptExecutor)EngineGloblalVariables.iwdCurrentlyUsedDriver).ExecuteScript("return document.readyState").ToString();
if (test.Equals("complete"))
return true;
return false;
}
catch
{
return false;
}
});
}
在驱动程序导航到页面后使用第二种解决方案。在使用 Firefox 时,我成功地使用了第二种解决方案,但 Chrome 在 60 秒后仍然超时。有没有其他方法可以设置或更改页面加载的默认超时?
编辑:
异常信息:
The HTTP request to the remote WebDriver server for URL
http://localhost:14545/session/4e0f1edcbc87d06360b6c89a06574476/buttonup timed out after
60 seconds.
【问题讨论】:
-
“超时”,用什么?请完整的错误和堆栈跟踪。
-
我编辑了帖子并添加了异常消息。我无法添加整个堆栈跟踪,因为测试是通过没有 Visual Studio 的远程服务器上的应用程序运行的,并且该服务器是唯一一个足够慢以获取此异常的服务器。修复了“超时”:D
标签: c# selenium timeout pageload selenium-chromedriver