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
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.
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.
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?
The setScriptTimeout is the method to set the time for the webdriver. This is usually applied for an asynchronous test to complete prior throwing an exception. The default value of timeout is 0. This method is generally used for JavaScript commands in Selenium.
The pageLoadTimeout is the method used to set the time for the entire page load prior to throwing an exception. If the timeout time is set to negative, then the time taken to load the page is endless. This timeout is generally used with the navigate and manage methods.
1. implicitlyWait() This timeout is used to specify the amount of time the driver should wait while searching for an element if it is not immediately present.
This defines the amount of time that Selenium will wait for a page to load. By default, it is set to 0 (which equates to an infinite time out).
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
Note: driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5))
is now deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With