How to set Page Load Timeout using C using Selenium WebDriver

0 votes

I want 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.

How to avoid this problem?

Aug 2, 2018 in Selenium by Martin
• 4,320 points
12,467 views

The solution for C#. Hope, it`ll help somebody.

   driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);  //time to wait untill page is loaded
   try
   {
      driver.Navigate().GoToUrl(url);  //if page is not loaded in 10 sec exception is thrown
   }
   catch
   {
      //catch timeout exception
   }

3 answers to this question.

0 votes

C# WebDriver API now contains the appropriate method.

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

answered Aug 2, 2018 by Samarpit
• 5,910 points
This does not work