Get an attribute of a selenider_element
object.
elem_attr()
returns a single attribute value as a string.
elem_attrs()
returns a named list containing every attribute.
elem_value()
returns the 'value' attribute.
Usage
elem_attr(x, name, default = NULL, timeout = NULL)
elem_attrs(x, timeout = NULL)
elem_value(x, ptype = character(), timeout = NULL)
Arguments
- x
A
selenider_element
object.- name
The name of the attribute to get; a string.
- default
The default value to use if the attribute does not exist in the element.
- timeout
The time to wait for
x
to exist.- ptype
The type to cast the value to. Useful when the value is an integer or decimal number. By default, the value is returned as a string.
Value
elem_attr()
returns a character vector of length 1. elem_attrs()
returns a named list of strings. The return value of elem_value()
has the
same type as ptype
and length 1.
See also
Other properties:
elem_css_property()
,
elem_name()
,
elem_size()
,
elem_text()
Examples
html <- "
<a class='link' href='https://r-project.org'>R</a>
<input type='number' value='0'>
"
session <- minimal_selenider_session(html)
s("a") |>
elem_attr("href")
s("a") |>
elem_attrs()
s("input[type='number']") |>
elem_value(ptype = integer())