This function essentially turns x
into:
list(x[[1]], x[[2]], ...)
However, to do this, the length of x
must be computed. This means that
while each element inside the list is still lazy, the list itself cannot be
considered lazy, since the number of elements in the DOM may change. To
avoid problems, it is recommended to use an element list just after it is
created, to make sure the list is an accurate representation of the DOM
when it is being used.
Usage
# S3 method for selenider_elements
as.list(x, timeout = NULL, ...)
Arguments
- x
A
selenider_elements
object.- timeout
How long to wait for
x
to exist while computing its length.- ...
Not used.
Details
Transform a selenider_elements
object into a list of
selenider_element
objects. The result can then be used in for loops and
higher order functions like lapply()
/purrr::map()
(whereas a
selenider_element
object cannot).
See also
elem_flatten()
to combine multipleselenider_element
/selenider_elements
objects into a single object.find_each_element()
andfind_all_elements()
to select elements using an element collection while preserving laziness.
Examples
html <- "
<div id='div1'>
<p>Text 1</p>
</div>
<div id='div2'>
<p>Text 2</p>
</div>
<div id='div3'>
<p>Text 3</p>
</div>
<div id='div4'>
<p>Text 4</p>
</div>
"
session <- minimal_selenider_session(html)
p_tags <- ss("p")
for (elem in as.list(p_tags)) {
print(elem_text(elem))
}
p_tags |>
as.list() |>
lapply(elem_text)