问题描述
我正在使用 Selenium 2.20 WebDriver 创建和管理带有 C# 的 firefox 浏览器.要访问一个页面,我使用以下代码,在访问 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
问题是有时页面加载需要很长时间,而且使用 selenium 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?
推荐答案
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
注意:driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5))
现已弃用.
这篇关于Selenium WebDriver - 如何使用 C# 设置页面加载超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!