Combine a set of selenider_element
/selenider_elements
objects
into a single selenider_elements
object, allowing you to
perform actions on them at once. c()
and elem_flatten()
do the same
thing, but elem_flatten()
works when given a list of
selenider_element
/selenider_elements
objects.
Arguments
- ...
<
dynamic-dots
>selenider_element
orselenider_elements
objects to be combined, or lists of such objects.
See also
as.list.selenider_elements()
to iterate over element collections.
Examples
html <- "
<div id='id1'></div>
<div class='.class2'></div>
<button id='button1'>Click me!</button>
<div class='button-container'>
<button id='button2'>No, click me!</button>
</div>
"
session <- minimal_selenider_session(html)
button_1 <- s("#button1")
button_2 <- s("#button2")
buttons <- elem_flatten(button_1, button_2)
buttons |>
elem_expect_all(is_enabled)
buttons |>
as.list() |>
lapply(elem_click)
# Doesn't just have to be single elements
first_2_divs <- ss("div")[1:2]
elem_flatten(first_2_divs, button_2) |>
length()
# We would like to use multiple css selectors and combine the results
selectors <- c(
"#id1", # Will select 1 element
"button", # Will select 2 elements
"p" # Will select 0 elements
)
lapply(selectors, ss) |>
elem_flatten() |>
length() # 3