Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll down the page till bottom(end page) in the Selenium WebDriver

Tags:

I need to scroll down page till end in the Selenium WebDriver. I tried to scroll down the page by using the following code snippet:

JavascriptExecutor jse6 = (JavascriptExecutor) driver; jse6.executeScript("window.scrollBy(0,250)", ""); 

It's being scrolled but I need to scroll down till end page.

like image 309
Prashanth Avatar asked Mar 23 '17 17:03

Prashanth


People also ask

How do you scroll down to the bottom of a page in Selenium?

Selenium runs the commands in Javascript with the execute_script() method. For scrolling down to the bottom of the page, we have to pass (0, document. body. scrollHeight) as parameters to the method scrollBy().

How do you scroll down a page?

Scroll one page at a time in all major browsers including Microsoft Internet Explorer and Mozilla Firefox by pressing the Spacebar key. Move back up the page by pressing Shift + Spacebar or the Home key on the keyboard.

How do I scroll down in Selenium using actions class?

We can perform scroll up/down a page using Actions class in Selenium webdriver. First of all, we have to create an object of this Actions class and then apply the sendKeys method on it. Now, to scroll down a page, we have to pass the parameter Keys. PAGE_DOWN to this method.


1 Answers

We have to use JavascriptExecutor

To scroll using coordinate

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)"); 

To scroll till end of the page

((JavascriptExecutor) driver)      .executeScript("window.scrollTo(0, document.body.scrollHeight)"); 

To scroll till any element

((JavascriptExecutor) driver).executeScript(             "arguments[0].scrollIntoView();", element); 
like image 200
shubham bansal Avatar answered Oct 25 '22 08:10

shubham bansal