xpath

open suspend override fun xpath(xpath: String, timeout: Long): List<Element>

Finds elements by XPath string.

If not immediately found, retries are attempted until timeout is reached (default 10 seconds). In case nothing is found, it returns an empty list. It will not throw. This timeout mechanism helps when relying on some element to appear before continuing your script.

Example usage:

// Find all the inline scripts (script elements without src attribute)
tab.xpath("//script[not(@src)]")

// More complex, case-insensitive text search
tab.xpath("//text()[ contains( translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'test')]")

Return

List of found Elements, or an empty list if none found within the timeout.

Parameters

xpath

The XPath string to search for.

timeout

The maximum time in milliseconds to wait for elements to appear before returning. Default is 10 seconds.