Get the element associated with a selenider element
Source:R/get_actual_element.R
get_actual_element.Rd
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.
Arguments
- x
A
selenider_element
orselenider_elements
object, produced byfind_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()
andfind_elements()
to select selenider elements.elem_cache()
andelem_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()
}