1

In reference to answer: https://stackoverflow.com/a/7811812/3146582

Does waiting for random page element being found by

_wait.Until(d => d.FindElement(By.Id("Id_Your_UIElement"));

really confirms that page was already fully loaded?

As fully loaded I assume:

  • all required and designed elements are now displayed
  • browser is not downloading any more data for that page
Community
  • 1
  • 1
Tomek
  • 701
  • 2
  • 8
  • 20
  • 1
    You can use the previous answer on the same post: [here](http://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium/34146048#34146048). Just to add, DOM property of readyState has 5 options viz: 1 - **uninitialized** - Has not started loading yet - 2 -**loading** - Is loading - 3 -**loaded** - Has been loaded - 4 -**interactive** - Has loaded enough and the user can interact with it - 5 -**complete** - Fully loaded – Vivek Singh Jan 28 '16 at 13:27
  • Thank you for the detailed information, it all seem to fit my expectations fully :) – Tomek Jan 29 '16 at 10:05

5 Answers5

2

No, it does not necessarily mean that the page is "fully loaded." All a successful call to findElement tells you is that element is loaded in the DOM. If you choose the element correctly, it may imply the page is fully loaded as defined by your criteria, but that will be entirely dependent on the page structure. For example, I could envision a page that fires off an XmlHttpRequest in JavaScript that's executed via setTimeout. The findElement call might succeed, but the page could still be downloading resources via that mechanism. This is one reason why there is no one-size-fits-all definition of "the page is fully loaded" in today's web. It depends on the page in question.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
1

Option 1:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(120));

Option 2:

WebDriverWait wait;
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
0

Use pageLoadTimeout to determine if page has been fully downloaded. Identify what's the page load expected delay from your specifications and use that time as your timeout while using this method.

Maertin
  • 384
  • 1
  • 8
  • don't you think it's not reliable test? we don't take under consideration random internet connection issues (slowdown), random extra-long downloading of one or more elements etc? – Tomek Jan 28 '16 at 13:17
  • Then just put timeout in excess of 10 minutes. – Maertin Jan 28 '16 at 13:51
0

It's quite impossible to define a generic fully loaded state for all web applications because of lazy-loading component. There are a couple practices that I use to define the loaded state. 1. Repeat counting web elements on the page until the number is stable. 2. Wait for the slowest component on the page.

Buaban
  • 5,029
  • 1
  • 17
  • 33
  • I assume that lazy-loading is used to upload page elements that are not required from the early start of the page – Tomek Jan 29 '16 at 10:04
  • When the web app has a lot of components, you don't have to process and render them all at once. You should show the top priority components first, then process the others later. In this case, you won't know what is "fully loaded" state of your app unless you keep checking state of all components in your app. Hence I give you the 2 practices that I use to determine if the web app is loaded or not. – Buaban Jan 29 '16 at 10:15
0

Selenium blocks the code until it receive page load notification from the DOM. You can limit the time by using pageLoadTimeout.

However that doesn't mean the elements are visible, only exist. To make sure they are displayed you should use explicit wait with expected conditions. For example

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("id")));

This will wait for your element to be visible, i.e. the element is displayed and has a height and width that is greater than 0.

It also doesn't mean the page can't change anymore. JavaScript may start to run only after the page is fully loaded and change the page.

For more information look here.

Guy
  • 46,488
  • 10
  • 44
  • 88