Using JavaScript
Scroll down:
Import Org.openqa.selenium.JavascriptExecutor;
Webdriver Driver = new Firefoxdriver ();
Javascriptexecutor JSE = (javascriptexecutor) driver;
Jse.executescript ("Scroll (0, 250)"); Y value ' + ' can be altered
Scroll up:
Javascriptexecutor JSE = (javascriptexecutor) driver;
Jse.executescript ("Scroll (250, 0)"); X value ' + ' can be altered
Scroll Bottom of the Page:
Javascriptexecutor JSE = (javascriptexecutor) driver;
Jse.executescript ("Window.scrollto (0,math.max (document.documentelement.scrollheight,document.body.scrollheight , document.documentElement.clientHeight)); ");
(OR)
actions = new actions (driver);
Actions.keydown (Keys.control). SendKeys (Keys.end). Perform ();
Full Scroll to bottom in slow motion:
for (int second = 0;; second++) {
if (second >=60) {
Break
}
((Javascriptexecutor) driver). Executescript ("Window.scrollby (0,400)", ""); Y value ' x ' can be altered
Thread.Sleep (3000);
}
(OR)
Javascriptexecutor JSE = (javascriptexecutor) driver;
for (int second = 0;; second++) {
if (second >=60) {
Break
}
Jse.executescript ("Window.scrollby (0,800)", ""); Y value ' + ' can be altered
Thread.Sleep (3000);
}
Scroll automatically to your webelement:
Point Hoveritem =driver.findelement (By.xpath ("Value")). GetLocation ();
((Javascriptexecutor) driver). Executescript ("return window.title;");
Thread.Sleep (6000);
((Javascriptexecutor) driver). Executescript ("Window.scrollby (0," + (Hoveritem.gety ()) + ");
Adjust your Page view by making changes right over here (Hoveritem.gety ()-400)
(OR)
((Javascriptexecutor) driver). Executescript ("Arguments[0].scrollintoview ();", Driver.findelement (By.xpath ("Value ‘)]")));
(OR)
webelement element = Driver.findelement (By.xpath ("Value"));
coordinates coordinate = ((locatable) Element). Getcoordinates ();
Coordinate.onpage ();
Coordinate.inviewport ();
Using KeyBoard
We have both options for scrolling in Web page. Using Actions Class
Package name:org.openqa.selenium.interactions.Actions Java code:
ctrl+end | Scroll to Bottom of the page
actions = new actions (driver);
Actions.keydown (Keys.control). SendKeys (Keys.end). Perform ();
Without Using Actions Class Java code:
For (int i=0;i<10;i++)
{
driver.findelement (By.tagname ("Body")). SendKeys (Keys. down);
}
Page Scroll using Selenium webdriver