elem_scroll_to {selenider} | R Documentation |
Scroll to an element
Description
Scrolls to an HTML element.
Usage
elem_scroll_to(x, js = FALSE, timeout = NULL)
Arguments
x |
A |
js |
Whether to scroll to the element using JavaScript. |
timeout |
How long to wait for the element to exist. |
Value
x
, invisibly.
See Also
Other actions:
elem_click()
,
elem_hover()
,
elem_select()
,
elem_set_value()
,
elem_submit()
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!"))
[Package selenider version 0.4.0 Index]