Skip to main content
BasePage is the foundation of the Page Object Model in this framework. Every page class extends it to inherit a set of Selenium wrapper methods that apply a 10-second explicit wait before each interaction, eliminating timing-related flakiness without requiring any extra setup in your page objects.

Constructor

public BasePage(WebDriver driver)
Initializes driver and creates a WebDriverWait with a 10-second timeout. PicoContainer injects the shared WebDriver instance when Cucumber instantiates a page object.
// Typical page object extending BasePage
public class HomePage extends BasePage {
    public HomePage(WebDriver driver) {
        super(driver);
    }
}

Methods

find

protected WebElement find(By locator)
Waits until the element is visible in the DOM, then returns it. This is a protected helper used internally by the other methods; call it from subclasses when you need the raw WebElement.
locator
By
required
A Selenium By locator that identifies the target element (e.g., By.id("username"), By.cssSelector(".btn-primary")).
WebElement
WebElement
The first matching element that is visible on screen.
Throws TimeoutException if the element does not become visible within 10 seconds.
// Inside a subclass
WebElement header = find(By.cssSelector("h1.page-title"));
String text = header.getText();

click

public void click(By locator)
Waits until the element is clickable (visible and enabled), then performs a click. Use this for buttons, links, checkboxes, and any other interactive element.
locator
By
required
A Selenium By locator for the element to click.
Throws TimeoutException if the element does not become clickable within 10 seconds.
click(By.id("submit-btn"));
click(By.linkText("Sign in"));

type

public void type(By locator, String text)
Clears the current value of an input field, then types the provided text. This method calls find() first, so it also waits for the field to be visible before interacting.
locator
By
required
A Selenium By locator for the <input> or <textarea> element.
text
String
required
The string to type into the field. The field is cleared before typing.
clear() is called before sendKeys(), so any pre-existing value is always replaced.
type(By.name("email"), "[email protected]");
type(By.id("first-name"), "Maria");

getText

public String getText(By locator)
Waits for the element to be visible, then returns its visible inner text.
locator
By
required
A Selenium By locator for the element whose text you want to read.
String
String
The trimmed visible text content of the element, as returned by WebElement.getText().
String errorMessage = getText(By.cssSelector(".error-msg"));
assertEquals(errorMessage, "Este campo es obligatorio.");

locatorText

public String locatorText(By locator)
Functionally identical to getText. It exists as an alias for readability in certain step definitions.
locator
By
required
A Selenium By locator for the element whose text you want to read.
String
String
The visible text of the element. Delegates directly to getText(locator).
Prefer getText in new code. Use locatorText only when it improves the readability of an existing step.
String label = locatorText(By.cssSelector("label[for='birthdate']"));

isDisplayed

public boolean isDisplayed(By locator)
Checks whether an element is visible. Catches any exception (including NoSuchElementException and TimeoutException) and returns false instead of throwing, making it safe to use in assertions and conditional logic.
locator
By
required
A Selenium By locator for the element to inspect.
boolean
boolean
true if the element exists and is visible; false if it is absent, hidden, or the wait times out.
boolean visible = isDisplayed(By.id("cookie-banner"));
if (visible) {
    click(By.id("accept-cookies"));
}

isClickable

public boolean isClickable(By locator)
Checks whether an element is enabled and ready to receive a click. Uses ExpectedConditions.elementToBeClickable internally. Returns false if the wait expires or any exception is raised.
locator
By
required
A Selenium By locator for the element to check.
boolean
boolean
true if the element is clickable within the 10-second timeout; false otherwise.
boolean enabled = isClickable(By.id("next-step-btn"));
assertTrue(enabled, "The 'Next step' button should be enabled");

isChecked

public boolean isChecked(By locator)
Checks whether a checkbox or radio button is selected. Catches any exception and returns false safely.
locator
By
required
A Selenium By locator for an <input type="checkbox"> or <input type="radio"> element.
boolean
boolean
true if the input is selected; false if it is unchecked or not found.
boolean accepted = isChecked(By.id("terms-checkbox"));
assertTrue(accepted, "Terms checkbox should be checked after clicking");

public void navigateTo(String url)
Navigates the current browser window to the given URL. Equivalent to driver.get(url); no explicit wait is applied because page-load behavior is controlled by the browser’s implicit page-load timeout.
url
String
required
The full URL to navigate to, including the scheme (e.g., "https://www.riu.com/es").
navigateTo("https://www.riu.com/es");
// or via a step
navigateTo("https://www.riu.com/es/hoteles");

Protected fields

FieldTypeDescription
driverWebDriverThe active browser session injected by PicoContainer.
waitWebDriverWaitExplicit wait configured with a 10-second timeout.
Both fields are protected so that subclasses can access them directly when the public wrapper methods are not sufficient (for example, when building a Select object or performing JavaScript execution).

Build docs developers (and LLMs) love