scroll_to method

Future<Online> scroll_to(
  1. AbstractSelector selector
)

Implementation

Future<Online> scroll_to(AbstractSelector selector) async {
  Show.action('scrolling', 'to', selector.selector);
  var selected = selector is XPath
      ? await (await page).waitForXPath(selector.selector, visible: true)
      : await (await page).waitForSelector(selector.selector, visible: true);
  if (selected != null) {
    //scroll to the element make sure it is effective and everything loads (wait)
    await selected.evaluate('''element => {
    element.scrollIntoView({behavior: "auto", block: "center", inline: "center"});
  }''');
  }
  //let everything load
  await Future.delayed(Duration(milliseconds: 500));
  return this;
}