find_element {selenider} | R Documentation |
Find a single HTML child element
Description
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,
...
)
Arguments
x |
A selenider session or element. |
... |
Arguments passed to methods. |
css |
A css selector. |
xpath |
An XPath. |
id |
The id of the element you want to select. |
class_name |
The class name of the element you want to select. |
name |
The name attribute of the element you want to select. |
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.
Value
A selenider_element
object.
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")