Element

interface Element

Represents a DOM element in the browser.

This class provides methods to interact with the DOM element, such as clicking, sending keys, and applying JavaScript functions. It also provides properties to access the element's tag name, text content, and position in the viewport.

Inheritors

Properties

Link copied to clipboard
abstract val attrs: List<String>

Returns a list of attributes of the element.

Link copied to clipboard
abstract val backendNodeId: Int

The internal node ID of the element in the DOM tree.

Link copied to clipboard
abstract val children: List<Element>

Returns the elements' children. Those children also have a children property so you can browse through the entire tree as well.

Link copied to clipboard
abstract val node: DOM.Node

The underlying DOM node representing this element.

Link copied to clipboard
abstract val nodeType: Int
Link copied to clipboard
abstract val objectId: String?
Link copied to clipboard
abstract val parent: Element?
Link copied to clipboard
abstract val parentId: Int?
Link copied to clipboard
abstract val tag: String

The name of the tag of the element, in lowercase.

Link copied to clipboard
abstract val text: String

The text content of the element, which is the concatenation of all text nodes within the element, excluding any HTML tags.

Link copied to clipboard
abstract val textAll: String

Gets the text contents of this element, and it's children in a concatenated string NOTE: this includes text in the form of script content, as those are also just 'text nodes'

Link copied to clipboard
abstract val tree: DOM.Node?

The DOM tree in which this element resides.

Functions

Link copied to clipboard
inline suspend fun <T> Element.apply(jsFunction: String, awaitPromise: Boolean = false): T?

Applies a JavaScript function to the element and returns the result. The given js_function string should accept the js element as parameter, and can be a arrow function, or function declaration.

Link copied to clipboard
abstract suspend fun clearInput()

Clears the input of the element by setting its value to an empty string.

Link copied to clipboard
abstract suspend fun clearInputByDeleting()

Clears the input of the element by simulating a series of delete key presses.

Link copied to clipboard
abstract suspend fun click()

Clicks the element, simulating a user click.

Link copied to clipboard
abstract suspend fun focus()

Focuses the element, making it the active element in the document.

Link copied to clipboard
abstract operator fun get(name: String): String?

Returns the value of the attribute with the given name, or null if it does not exist.

Link copied to clipboard
abstract suspend fun getPosition(abs: Boolean = false): Position?

Retrieves the position of the element in the viewport.

Link copied to clipboard
abstract suspend fun insertText(text: String)

Inserts text into the element, simulating user input.

Link copied to clipboard
abstract suspend fun mouseMove()

Moves the mouse to the center of the element and simulates a mouse click.

Link copied to clipboard
abstract suspend fun querySelector(selector: String): Element?

Finds the first descendant element matching the given CSS selector, similar to JavaScript's querySelector().

Link copied to clipboard
abstract suspend fun querySelectorAll(selector: String): List<Element>

Finds all descendant elements matching the given CSS selector, similar to JavaScript's querySelectorAll().

Link copied to clipboard
abstract suspend fun rawApply(jsFunction: String, awaitPromise: Boolean = false): JsonElement?

Applies a JavaScript function to the element and returns the result. The given js_function string should accept the js element as parameter, and can be a arrow function, or function declaration.

Link copied to clipboard
abstract suspend fun sendFile(paths: List<Path>)

Sends a list of file paths to the element, simulating a file input.

Link copied to clipboard
abstract suspend fun sendKeys(text: String)

Sends a sequence of keys to the element, simulating user input.

Link copied to clipboard
Link copied to clipboard
abstract override fun toString(): String

Returns a string representation of the element, including its tag name, attributes, and content.

Link copied to clipboard
abstract suspend fun update(nodeOverride: DOM.Node? = null): Element

Updates the element to retrieve more properties, such as enabling the children and parent attributes.

Link copied to clipboard
abstract suspend fun updateRemoteObject(): Runtime.RemoteObject?