js scrollIntoView code example

Example 1: javascript scrollintoview

var element = document.getElementById("box");

element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});

Example 2: scroll down to element if not visible

WebDriver driver = new ChromeDriver(); 
JavascriptExecutor jse =(JavascriptExecutor)driver
.jse.executeScript('window.scrollBy(0,250)', ’’);

Example 3: scrollintoview

element.scrollIntoView();
element.scrollIntoView(alignToTop); // Boolean parameter
element.scrollIntoView(scrollIntoViewOptions); // Object parameter