get_actual_element: Get the element associated with a selenider element

View source: R/get_actual_element.R

get_actual_elementR Documentation

Get the element associated with a selenider element

Description

Turn a lazy selenium element or element collection into a backendNodeId (chromote) or a selenium::WebElement. Use this to perform certain actions on the element that are not implemented in selenider.

get_actual_element() turns a selenider_element object into a single backendNodeId or selenium::WebElement object. The function will wait for the object to exist in the DOM.

get_actual_elements() turns a selenider_elements object into a list of selenium::WebElement objects, waiting for any parent objects to exist in the DOM.

Usage

get_actual_element(x, timeout = NULL)

get_actual_elements(x, timeout = NULL)

Arguments

x

A selenider_element or selenider_elements object, produced by find_element() / find_elements().

timeout

The timeout to use while asserting that the item exists. If NULL, the timeout of the selenider_element will be used.

Value

An integer (backendNodeId), or a selenium::WebElement object. get_actual_elements() returns a list of such objects.

See Also

  • s(), ss(), find_element() and find_elements() to select selenider elements.

  • elem_cache() and elem_cache() to cache these values.

  • The Chrome Devtools Protocol documentation for the operations that can be performed using a backend node id. Note that this requires the chromote::ChromoteSession object, which can be retrieved using ⁠<selenider_session>$driver⁠.

  • The documentation for selenium::WebElement() to see the things you can do with a webElement.

Examples


html <- "
<div>
<p>Text</p>
<p>More text</p>
</div>
"

session <- minimal_selenider_session(html)

elem <- s("div") |>
  get_actual_element()

# The ChromoteSession/SeleniumSession can be accessed using session$driver
driver <- session$driver

if (inherits(driver, "ChromoteSession")) {
  driver$DOM$getBoxModel(backendNodeId = elem)
} else if (inherits(elem, "WebElement")) {
  elem$get_rect()
}

elems <- ss("p") |>
  get_actual_elements()

if (inherits(driver, "ChromoteSession")) {
  driver$DOM$describeNode(backendNodeId = elems[[1]])
} else if (inherits(elems[[1]], "WebElement")) {
  elems[[1]]$get_rect()
}


selenider documentation built on April 3, 2025, 5:51 p.m.