Find the first HTML element using a CSS selector, an XPath, or a variety of other methods.
Usage
find_element(x, ...)
# S3 method for class 'selenider_session'
find_element(
x,
css = NULL,
xpath = NULL,
id = NULL,
class_name = NULL,
name = NULL,
...
)
# S3 method for class 'selenider_element'
find_element(
x,
css = NULL,
xpath = NULL,
id = NULL,
class_name = NULL,
name = NULL,
...
)
Details
If more than one method is used to select an element (e.g. css
and
xpath
), the first element which satisfies all conditions will be found.
CSS selectors are generally recommended over other options, since they are
usually the easiest to read. Use "tag_name"
to select by tag name,
".class"
to select by class, and "#id"
to select by id.
See also
s()
to quickly select an element without specifying the session.find_elements()
to select multiple elements.selenider_session()
to begin a session.
Examples
html <- "
<div class='class1'>
<div id='id1'>
<p class='class2'>Example text</p>
</div>
<p>Example text</p>
</div>
"
session <- minimal_selenider_session(html)
session |>
find_element("div")
session |>
find_element("div") |>
find_element(xpath = "./p")
s("div") |>
find_element("#id1")
s("div") |>
find_element(id = "id1") |>
find_element(class_name = "class2")
s(xpath = "//div[contains(@class, 'class1')]/div/p")
# Complex Xpath expressions are easier to read as chained CSS selectors.
# This is equivalent to above
s("div.class1") |>
find_element("div") |>
find_element("p")