Skip to main content

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.

note

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.

ConfigurationPolling intervalTimeoutDefault messageIgnoresDescription
DEFAULT200 milliseconds10 seconds"Element could not be found"NoSuchElementExceptionA wait configuration suitable for most web automation scenarios.
QUICK100 milliseconds2 seconds"Element could not be found"NoSuchElementExceptionA fast wait configuration for responsive applications.
PATIENT500 milliseconds30 seconds"Element could not be found"NoSuchElementExceptionAn 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 negative
  • pollingInterval is less than 10 milliseconds
  • timeout is negative
  • timeout is less than 100 milliseconds
  • pollingInterval is greater than timeout