Configuring waiting behavior
Kolibrium provides an option to configure the waiting behavior when looking up elements by specifying polling interval, timeout, error message, and which exceptions to ignore during the wait.
val className by driver.className(
locator = "by-class-name",
wait = Wait(
pollingInterval = 250.milliseconds,
timeout = 5.seconds,
message = "Element could not be found",
ignoring = listof(NoSuchElementException::class),
)
)
Under the hood, a FluentWait
instance is being configured for the element lookup.
Ensure that org.openqa.selenium.NoSuchElementException
is imported. If it isn't listed among the imports, it means the java.util.NoSuchElementException
class has been imported instead. This results in a wait configuration that fails to work as intended, as it waits for the wrong exception.
Additionally, since Kolibrium relocates the element by default when a StaleElementReferenceException
occurs, you don't need to include StaleElementReferenceException
in the ignored exceptions list.
Predefined wait configurations for common use cases
There are three predefined wait configurations that can be used as they are defined or modified through the copy()
function.
Configuration | Polling interval | Timeout | Default message | Ignores | Description |
---|---|---|---|---|---|
DEFAULT | 200 milliseconds | 10 seconds | "Element could not be found" | NoSuchElementException | A wait configuration suitable for most web automation scenarios. |
QUICK | 100 milliseconds | 2 seconds | "Element could not be found" | NoSuchElementException | A fast wait configuration for responsive applications. |
PATIENT | 500 milliseconds | 30 seconds | "Element could not be found" | NoSuchElementException | An extended wait configuration for slower applications or operations that might take longer to complete. |
Customizing wait configurations
The copy()
function allows you to easily modify existing wait configurations. You can change any combination of
pollingInterval
timeout
message
ignoring
(list of exceptions to ignore)
val className by driver.className(
locator = "by-class-name",
wait = DEFAULT.copy(
pollingInterval = 250.milliseconds,
message = "Custom timeout message",
ignoring = listOf(
NoSuchElementException::class,
ElementNotInteractableException::class
)
)
)
Potential configuration errors
The Wait
configuration includes runtime checks that will throw an IllegalArgumentException
if:
pollingInterval
is negativepollingInterval
is less than 10 millisecondstimeout
is negativetimeout
is less than 100 millisecondspollingInterval
is greater thantimeout