页面加载超时 - 硒的webdriver使用C# [英] Page Load Timeout - Selenium Webdriver using C#

查看:1210
本文介绍了页面加载超时 - 硒的webdriver使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的硒2.25的webdriver

I am using Selenium 2.25 WebDriver

我在与发现页面上的元素和一些时间我的测试案例能够找到元素,在某个时候一个问题网页是不会加载其因页面加载,如果我在下面添加行这一点,好像工作:

I'm having a issue with finding the elements on the page and some times my test cases able to find element and sometime the page is does not load and its due to page load and if i add this below line and it seems like working:

 driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));



我的问题是,我不希望有我的代码分散与上面的代码行,是有一个办法让它在一个地方centerlize?

my question is, i dont want to have my code scatter with the above line of code, is there a way to make it centerlize in one place?

任何帮助将不胜感激,谢谢!

Any help would be greatly appreciated, thanks!

推荐答案

如果你设置超时一次,它被设置为驱动程序实例的生命周期。你并不需要保持其复位。你可以创建驱动程序后,立即设置该

If you set the timeout once, it's set for the lifetime of the driver instance. You don't need to keep resetting it. You can set this immediately after creating the driver.

IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts.SetPageLoadTimeout(TimeSpan.FromSeconds(2));

有关使用此超时唯一需要注意的是,并不是所有的浏览器可能会完全支持它(IE浏览器肯​​定,Firefox没有太多我想,但我不认为Chrome的那样)。

The only caveat for using this timeout is that not every browser may support it completely (IE does for sure, Firefox does too I think, but I don't think Chrome does).

这篇关于页面加载超时 - 硒的webdriver使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆