find_element | R Documentation |
Find the first HTML element using a CSS selector, an XPath, or a variety of other methods.
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,
...
)
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. |
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.
A selenider_element
object.
s()
to quickly select an element without specifying the session.
find_elements()
to select multiple elements.
selenider_session()
to begin a session.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.