硒的webdriver - 如何使用C#来设置页面加载超时 [英] Selenium WebDriver - How to set Page Load Timeout using C#

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

问题描述

我使用的硒2.20 webdriver的创建和管理一个Firefox浏览器使用C#。要访问一个页面,我使用下面的代码,设置驱动器访问URL之前超时:

I am using Selenium 2.20 WebDriver to create and manage a firefox browser with C#. To visit a page, i use the following code, setting the driver timeouts before visiting the URL:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); // Set implicit wait timeouts to 5 secs
driver.Manage().Timeouts().SetScriptTimeout(new TimeSpan(0, 0, 0, 5));  // Set script timeouts to 5 secs
driver.Navigate().GoToUrl(myUrl);   // Goto page url

的问题是,有时网页需要永远载入,而现在看来,一个页面加载使用硒的webdriver默认的超时时间为30秒,这是太长。我不相信我设置适用于使用GoToUrl()方法的页面加载超时。

The problem is that sometimes pages take forever to load, and it appears that the default timeout for a page to load using the selenium WebDriver is 30 seconds, which is too long. And i don't believe the timeouts i am setting apply to the loading of a page using the GoToUrl() method.

所以我想弄清楚如何设置超时一个页面加载,但是,我无法找到实际工作的任何属性或方法。该默认为30秒超时似乎也适用于当我点击的元素。

So I am trying to figure out how to set a timeout for a page to load, however, i cannot find any property or method that actually works. The default 30 second timeout also seems to apply to when i click an element.

有没有办法在页面加载超时设置为一个特定的值,这样,当我打电话在GoToUrl()方法,它只会继续等待我的指定的时间?

Is there a way to set the page load timeout to a specific value so that when i call the GoToUrl() method it will only wait my specified time before continuing?

推荐答案

在情况下,这可以帮助任何人还在寻找答案这一点,在C#的webdriver API确实现在包含了适当的方法。

In case this helps anyone still looking for the answer to this, the C# WebDriver API does now contain the appropriate method.

driver.Manage().Timeouts().SetPageLoadTimeout(timespan)

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

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