Benjamin Ruan
Benjamin Ruan

Reputation: 81

How to measure the exact time to load a page using selenium or in C#?

In my cases, I want to measure the time it takes to load the full content of the webpage not just the basic page source. And those pages come from clicking to elements so driver.get("Some url"); may not work for me because the url of the target webpage is unknown ex. urlByText.Click();.

Is there any way I can do it?

Upvotes: 0

Views: 954

Answers (1)

ddavison
ddavison

Reputation: 29032

Not by default, no. Selenium really shouldn't be used to test this. This sort of testing should be accomplished by a tool that is designed for page-load times. Something like:

  • JMeter
  • Gomez

That being said, it isn't recommended to use Selenium, but it is possible.

You could achieve the results you want by first knowing what sort of js libraries that your app is using for its ajax calls.

Once you know that, you can detect and wait for all ajax calls to finish.

Something like (pseudo-code):

waitForJavaScript("(typeof Ajax == 'undefined' ? jQuery.active == 0 : Ajax.activeRequestCount == 0)")

But this won't give you the "real" page load, since you'd have to actively monitor those properties, and sometimes the properties wouldn't be there so you might find yourself waiting for an ajax event to happen, that never does. This results in not getting "realtime" loading results.

My opinion is to use a tool that is designed for this purpose. Not Selenium. Selenium is designed for automating the app. Not specifically caring about load times

Upvotes: 4

Related Questions