find_elements: Find multiple HTML child elements

View source: R/find_elements.R

find_elementsR Documentation

Find multiple HTML child elements

Description

Find every available HTML element using a CSS selector, an XPath, or a variety of other methods.

Usage

find_elements(x, ...)

## S3 method for class 'selenider_session'
find_elements(
  x,
  css = NULL,
  xpath = NULL,
  id = NULL,
  class_name = NULL,
  name = NULL,
  ...
)

## S3 method for class 'selenider_element'
find_elements(
  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 every condition will be found.

Value

A selenider_elements object. Note that this is not a list, and you should be careful with the functions that you use with it. See the advanced usage vignette for more details: vignette("advanced-usage", package = "selenider").

See Also

  • ss() to quickly select multiple elements without specifying the session.

  • find_element() to select a single element.

  • selenider_session() to begin a session.

  • elem_children() and family to select elements using their relative position in the DOM.

  • elem_filter() and elem_find() for filtering element collections.

  • as.list.selenider_elements() to convert a selenider_elements object to a list.

Examples


html <- "
<div id='outer-div'>
  <div>
    <p>Text 1</p>
    <p>Text 2</p>
    <p>Text 3</p>
  </div>
</div>

<div></div>
"

session <- minimal_selenider_session(html)

session |>
  find_elements("div")

# Or:
ss("div")

session |>
  find_element("#outer-div") |>
  find_elements("p")

# The above can be shortened to:
s("#outer-div") |>
  find_elements("p")


selenider documentation built on April 3, 2025, 5:51 p.m.