Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Measure your website's page load times with Selenium and improve user experience. Learn about our expert tips and tricks to accurately monitor and optimize your site's performance.

Himanshu Sheth
January 30, 2026
There are a number of metrics that are considered during the development & release of any software product. One such metric is the ‘user-experience’ which is centred on the ease with which your customers can use your product. You may have developed a product that solves a problem at scale, but if your customers experience difficulties in using it, they may start looking out for other options. Website or web application’s which offers better web design, page load speed, usability (ease of use), memory requirements, and more. Today, I will show you how you can measure page load time with Selenium for . Before doing that, we ought to understand the relevance of page load time for a website or a web app.
Loading time refers to the period from the browser’s request to the page fully loading and rendering. It includes ‘Time to first byte,’ which is the time between the request and the browser receiving the first data byte
More than 40 percent of the website visitors may leave if the loading time is more than 3 seconds. This is why your software development, design, and product development team should focus on improving the performance of your web product. Don’t believe me? Below, is an image from a study conducted by Google related to page load speed with respect to bounce rate
Popular search engines measure the time it takes for the receipt of the first byte in order to determine the site speed/page speed. Hence, slow rendering pages can have a huge hit on the search engine rankings. Slow page speed also means that the search engine crawler can crawl less number of pages within the allocated crawl budget, which would eventually show up in the rankings.
A fact known to most of us is that if a website offers a more mobile-friendly user experience with faster page load time on mobile, Google would value those websites more and rank them on top in mobile search results. For this purpose, Google came up with a new mobile-friendly algorithm on April 21, 2015. Therefore, it is important to test a mobile website for user-friendliness.
It is not just Google but your customers would also won’t prefer your website or web app if the pages on the website don’t load with the lightning fast pace. Even one-second delay in the page load time can result in higher bounce rates and reduced number of page-views. It also has a negative impact on Click Through Rates (CTR) and conversions. In simple terms, measuring page-load time (also referred to as Page Speed) is the amount of time it takes for the content/page to appear on the screen. Lower the page-load time, better is the usability factor of the product, better is your conversion rate.
Watch this video to learn about network interception using bidirectional APIs in Selenium 4.
Different pages on the same website/web-app can have different load times, depending on the design being used for the development of the pages. Developers might have used either of the techniques to reduce the page load time.
That is from the developers’ end, but how would you go about testing the website by measuring the page load time of every page?
There could be hundreds of webpages on your website. Not to forget, you would have to perform browser compatibility testing to realize the page load time of every page on your website across hundreds of browsers and browser versions.
There is a possibility that your web page load time will differ if accessed from different browsers (including browser versions). It would also depend on the platform (desktop, tablet, mobile, etc.) and the geographical location from where your website/web-app is being accessed. You can’t go about testing every combination(web page + browser + browser version + operating system) manually. This is where Selenium grid comes to the rescue by empowering you to perform automated cross browser testing of your web pages. You can perform automation testing for measuring page load time with Selenium. Before we do that, it is important to have a look at the Navigation Timing.
You can make use of Selenium to measure the performance of a web page over a period of time. The results that are obtained from the Navigation Timing API can be further used to improve the page load time with Selenium testing and also benchmark those results against your competitors’ web performance. Though there would be visible differences between the home page & functionalities provided by two websites/web-apps (solving a similar problem), it is still important that the page load speed is equal (if not better) than your competition.
Along with tracking & benchmarking the web-page performance, Selenium can also be used to log the statistics of the page to come up with improvements on the client-side. As far as the server side is concerned, major performance improvement can be obtained by making use of the right kind of infrastructure.
We have a look at another example where we load a web-page and search for the presence of an element (div-id) in the page. We search for the div-id for timeout duration of 5 seconds. Once the page is loaded, div-id (in our case: owl-example) is searched for 5 seconds, after which an exception is raised if the owl-example div-id is not present on the web-page. All the necessary modules are imported at the start of the implementation.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
''' Create a Chrome webdriver instance'''
driver = webdriver.Chrome()
#driver = webdriver.Firefox()
''' Open the webpage under test'''
driver.get('http://lambdatest.com')
timeout = 5
''''' Test case 1 - The required div-id is not present on the web-page '''''
#while True:
try:
element_present = EC.presence_of_element_located((By.ID, 'owl-example-1'))
WebDriverWait(driver, timeout).until(element_present)
print("1 - Element is present on the page")
# break
except TimeoutException as ex:
print("1 - Timed out waiting for page to load " + str(ex))
# break
''''' Test case 2 - The required div-id is not present on the web-page '''''
#while True:
try:
element_present = EC.presence_of_element_located((By.ID, 'owl-example'))
WebDriverWait(driver, timeout).until(element_present)
print("2 - Element is present on the page")
# break
except TimeoutException as ex:
print("2 - Timed out waiting for page to load " + str(ex))
# break
''' Free up the resources'''
driver.close()
driver.quit()
Like the previous example, we initialize the Chrome webdriver interface. The web-page under test is the TestMu AI homepage – lambdatest.com. The timeout duration is set to 5 seconds. There are two test-cases, details of which are mentioned below
Below is the output of the above example
As expected, the first test case fails as the div-id under search is not present on the web-page under test. The search times out after 5 seconds. On the other hand, the second test case passed since the div-id ‘owl-example’ is present on the web-page. For confirmation, please visit the HTML source of TestMu AI. (which is the page being tested) 
There would be scenarios where you need to perform an operation when a webpage is loaded i.e. document.readyState status as ‘complete’. The operation could either be clicking on a hyper-link or clicking on a button or any other operation. It could be a tricky situation as there might be scenarios where few sections of webpage are loaded asynchronously using AJAX (Asynchronous JavaScript and XML) on the client side. We focus on webpage operations where a new webpage is loaded. In this section of the Selenium testing tutorial, we have a look at the mechanism that Selenium uses to check whether the complete webpage is loaded.

Selenium has an in-built condition called staleness_of and its own wait_for implementation. staleness_of is the element of the selenium class selenium.webdriver.support.expected_conditions. staleness_of will wait until an element is not attached to the DOM. Below is the implementation of the class
class selenium.webdriver.support.expected_conditions.staleness_of(element)
element is the actual element on the webpage to wait for. It returns False if the element is attached to the DOM, else it returns True. We will make use of the pytest framework which we have already covered in earlier blogs. In the below example, @contextmanager is used which aids in allocating & releasing necessary resources when required.
''' Import the 'modules' that are required for execution '''
''' In this example, we make use of pytest framework along with Selenium '''
import pytest
import pytest_html
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from time import sleep
from contextlib import contextmanager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import staleness_of
@pytest.fixture(params=["chrome"],scope="class")
def driver_init(request):
if request.param == "chrome":
web_driver = webdriver.Chrome()
request.cls.driver = web_driver
yield
web_driver.close()
@pytest.mark.usefixtures("driver_init")
class BasicTest:
pass
class Test_URL(BasicTest):
def test_open_url(self):
self.driver.get("https://www.lambdatest.com/")
print(self.driver.title)
sleep(5)
@contextmanager
def wait_for_page_load(self, timeout=30):
#Search for the div-id owl-example
old_page = self.driver.find_element_by_id('owl-example')
yield
WebDriverWait(self.driver, timeout).until(
staleness_of(old_page)
)
def test_click_operation(self):
# Wait for a timeout duration of 10 seconds, after which we perform a CLICK operation
with self.wait_for_page_load(timeout=10):
self.driver.find_element_by_link_text('FREE SIGN UP').click()
print(self.driver.execute_script("return document.readyState"))
In wait_for_page_load(), search for the div-id owl-example is performed. WebDriverWait is used in combination with ExpectedCondition to achieve Explicit Wait condition. The driver and timeout are passed as arguments. We wait until the element gets stale. In case the element being searched i.e. owl-exampl’ is not present, a TimeoutException is thrown. This is how we check for the staleness of the element.
In test_click_operation(), the webpage lambdatest.com is loaded after which a wait for the maximum duration of 10 seconds is performed. It uses wait_for_page_load() to check whether the element owl-example on the webpage is not stale. Once the webpage is loaded within the timeout, we check if there is an element which has link text FREE SIGN UP which is a button that is hyperlinked to the registration page. Finally, we check the status of web page/document using the Document.readyState property. When the value of this particular property changes, a readystatechange event is fired on the document object.
The three possible states are loading, interactive, and complete. Document.readyState achieves the state as complete if the webpage/document & its dependent resources have finished loading. In our example, if the page is loaded completely, a button click is performed which eventually takes us to the TestMu AI registration page
For execution, py.test command is used with verbose enabled and –capture set to no
Depending on the target market and the browser that is responsible for bringing you the most traffic, you should create a cross browser testing matrix to perform cross browser testing in an organized manner. Cross browser testing of your product would help you with the findings of valuable test cases which can further be used for improving the page-load times. Rather than creating a local infrastructure to do these tests, you can make use of TestMu AI which offers scalable cross browser testing tool on the Cloud.
Measuring page load time is very important for web-based products since it has a direct impact on the user-experience. Along with optimizing the overall design of your product, it is important to design web pages in a manner that the page load times are kept to the minimum. This would improve the conversions expected out of the product.
Navigation Timing APIs are instrumental in keeping a measure of page load times. You can use the output generated by these APIs for optimization purpose. window. performance returns the performance object which gives important information about the current document/page. It can be used along with the Selenium framework. Measuring page load time with Selenium is critical as a web page can vary across different types & versions of browsers, hence it is important to focus on optimizing the page speed of your product on browsers & platforms for superior customer experience.
Enhance your Selenium interview proficiency with our meticulously curated compilation of questions and answers. Explore the comprehensive list of Selenium Interview Questions and Answers for valuable insights.

Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance