Skip to main content

Configuring waiting behavior

Kolibrium lets you fine-tune how long and how often it waits while locating elements. You can control polling interval, timeout, error message, and which exceptions to ignore using WaitConfig.

val className by driver.className(
value = "by-class-name",
waitConfig = WaitConfig.Default.copy(
pollingInterval = 250.milliseconds,
timeout = 5.seconds,
message = "Element could not be found"
)
)

Under the hood, a FluentWait instance is being configured for the element lookup.

note

Kolibrium automatically ignores org.openqa.selenium.NoSuchElementException during waits. You do not need to add it to WaitConfig.

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

Kolibrium provides three presets via WaitConfig: WaitConfig.Default, WaitConfig.Quick, and WaitConfig.Patient. You can use them as-is or tweak them with copy().

ConfigurationPolling intervalTimeoutDefault messageDescription
WaitConfig.Default200 milliseconds10 seconds"Condition not met within timeout"Balanced preset suitable for most scenarios.
WaitConfig.Quick100 milliseconds2 seconds"Condition not met within timeout"Fast preset for responsive applications.
WaitConfig.Patient500 milliseconds30 seconds"Condition not met within timeout"Extended waits for slower operations.

Customizing wait configurations

The copy() function allows you to easily modify existing wait configurations. You can change any combination of

  • pollingInterval
  • timeout
  • message
  • ignoring (set of exceptions to ignore)
val className by driver.className(
value = "by-class-name",
waitConfig = WaitConfig.Default.copy(timeout = 5.seconds)
)

Potential configuration errors

The WaitConfig 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