Skip to contents

Scrolls to an HTML element.

Usage

elem_scroll_to(x, js = FALSE, timeout = NULL)

Arguments

x

A selenider_element object.

js

Whether to scroll to the element using JavaScript.

timeout

How long to wait for the element to exist.

Value

x, invisibly.

See also

Examples

html <- "
<div style = 'height:100%; min-height:100vh'></div>
<button onclick='checkScrolled()'></button>
<p>Scroll down to find me!</p>
"

js <- "
function checkScrolled() {
  let element = document.getElementsByTagName('p').item(0);
  let rect = element.getBoundingClientRect();
  // If paragraph is in view
  const height = window.innerHeight || document.documentElement.clientHeight;
  if (rect.bottom <= height) {
    element.innerText = 'You found me!';
  }
}
"

session <- minimal_selenider_session(html, js = js)

s("p") |>
  elem_scroll_to()

s("button") |>
  elem_click()

elem_expect(s("p"), has_text("You found me!"))