| elem_filter | R Documentation |
Operators to extract a subset of elements, or a single element, from a selenider element collection.
elem_filter() and elem_find() allow you to use conditions to filter HTML
elements (see is_present() and other conditions). elem_find() returns
the first element that satisfies one or more conditions, while
elem_filter() returns every element that satisfies these conditions.
[ and [[ with a numeric subscript can be used on an element collection
to filter the elements by position. [ returns a single element at a
specified location, while [[ returns a collection of the elements at more
than one position.
elem_filter(x, ...)
elem_find(x, ...)
## S3 method for class 'selenider_elements'
x[i]
## S3 method for class 'selenider_elements'
x[[i]]
x |
A |
... |
< |
i |
A number (or for |
As with the find_element() and find_elements() functions, these
functions are lazy, meaning that the elements are not fetched and filtered
until they are needed.
Conditions can be functions or function calls (see elem_expect() for more
details).
elem_filter() and [ return a selenider_elements object, since they can
result in multiple elements.
elem_find() and [[ return a single selenider_element object.
find_elements() and ss() to get elements to filter.
is_present() and other conditions for predicates on HTML elements.
(If you scroll down to the See also section, you will find the rest).
html <- "
<button disabled>Button 1</button>
<button>Button 2</button>
<p>Text</p>
<div style='display:none;'></div>
"
session <- minimal_selenider_session(html)
elements <- ss("*")
# Gives the same result as s()
elements[[1]]
elements[1:3]
elements[-2]
elements |>
elem_filter(is_visible)
elements |>
elem_find(is_visible)
# The above is equivalent to:
visible_elems <- elements |>
elem_filter(is_visible)
visible_elems[[1]]
# In R >= 4.3.0, we can instead do:
# ss(".class1") |>
# elem_filter(is_visible) |>
# _[[1]]
ss("button") |>
elem_filter(is_enabled)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.