World’s largest virtual agentic engineering & quality conference

WHENAUG 19-21
WHEREVirtual · Global
Register Now
Automation

Loadable Components In Selenium: Make Your Test Robust For Slow Loading Web Pages

In the selenium library, Loadable Component class helps the automation test engineers to make sure that the page or its component is loaded successfully. This hack should greatly reduce the efforts that you put in debugging your test cases.

Author

Aditya Dwivedi

Author

Last Updated on: November 9, 2023

Being in automation testing for the last 10 years I have faced a lot of problems. Recently I was working on a selenium automation project and in that project everything was going fine until I faced a most common but difficult problem. How to make sure that my selenium automation testing work fine even for slow loading web pages. A quick google and browsing through forums highlighted that this is a problem that testers are facing for many past years. If you too have faced it then yes, this article is there to help you from my personal experience. Well, this problem is majorly observed in the case when the web application uses a javascript heavy framework.

The component that’s gonna help us in page loading is an extended version of PageObject pattern called Loadable component.In the selenium library, Loadable Component class helps the automation test engineers to make sure that the page or its component is loaded successfully. This hack should greatly reduce the efforts that you put in debugging your test cases.

On a side note, to make your life of testing easy and fuss-free while debugging, you can try the LT Debug Chrome extension.

To start with, we would first have to make sure that all the PageObject classes extends the abstract LoadableComponent class and in turn provide implementation for the following two methods:

  • protected abstract void load()
  • protected abstract void isLoaded() throws java.lang.Error

Code to ensure whether the page or component inside the page is completely loaded in given in isLoaded(). If the page is not completely loaded, java.lang.Error is thrown

Fallback or mitigation code is given load(), if isLoaded() fails to load the complete page successfully.

Let’s take an example on how it works :

Suppose, we have a LoginPage with username, password and submit button.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class LoginPage {

private WebDriver driver;

@FindBy(id = "login_username")
private WebElement usernameInputBox;

@FindBy(id = "login_password")
private WebElement passwordInputBox;

@FindBy(id = "login_submit")
private WebElement loginButton;

public AdminLoginPageUsingLoadableComponent(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}

public NextPage login(String loginUsername, String loginPassword){
usernameInputBox.sendKeys(loginUsername");
passwordInputBox.sendKeys(loginPassword");
loginButton.click();

return PageFactory.initElements(driver, NextPage.class);
}

}

Now, the above PageObject can be transformed using LoadableCompenent like below.

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.LoadableComponent;

public class LoginPageUsingLoadableComponent extends LoadableCompenent {

private WebDriver driver;

@FindBy(id = "login_username")
private WebElement usernameInputBox;

@FindBy(id = "login_password")
private WebElement passwordInputBox;

@FindBy(id = "login_submit")
private WebElement loginButton;

public LoginPageUsingLoadableComponent(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}

public NextPage login(String loginUsername, String loginPassword){
usernameInputBox.sendKeys(loginUsername");
passwordInputBox.sendKeys(loginPassword");
loginButton.click();

return PageFactory.initElements(driver, NextPage.class);
}

@Override
protected void load() {
driver.get("http://www.example.com/login");
}

@Override
protected void isLoaded() throws Error {
Assert.assertTrue(driver.getCurrentUrl().contains("login"));
}

}

LoginPageUsingLoadableComponent loginPage = new LoginPageUsingLoadableComponent(driver).get();

The get() method from the LoadableComponent class will ensure sure the page or the component is loaded by invoking the isLoaded() method. If the assertion fails there, load() method is called, followed by isLoaded().

Hope this article helps in stabilizing UI tests !!!

Austin Siewert

Austin Siewert

Co-Founder, Steadfast Systems

Discovered @TestMu AI yesterday. Best browser testing tool I've found for my use case. Great pricing model for the limited testing I do 👏

2M+ Devs and QAs rely on TestMu AI

Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud

Author

...

Aditya Dwivedi

Blogs: 7

  • Twitter
  • Linkedin

Aditya Kumar Dwivedi is a Senior QA Engineer with 7+ years of experience in manual testing, UI automation, and API testing across web and mobile applications. He specializes in automation framework development from scratch using Selenium, Playwright, Appium, REST Assured, and Cucumber, with strong experience integrating tests into CI/CD pipelines using Jenkins. Aditya has worked extensively in Agile environments, contributing to scalable test architectures, efficient testing workflows, and reliable software releases, including hands-on experience at TestMu AI.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free
...
TestMu Conf 2026

World's largest virtual agentic engineering & quality conference

...

AUG 19-21, 2026

REGISTER NOW

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests