Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+14 votes
7 views
in Java by (1.1k points)
edited by

I use Selenium RC, for which the scroll command  is

selenium.getEval("scrollBy(0, 250)");

Now, I have started using Selenium WebDriver , what will be the command for it?

closed

2 Answers

+13 votes
by (13.2k points)
edited by
 
Best answer

A scrollbar lets you move around the screen if the page does not fit the visible area of the screen, contrary to Selenium Webdriver in certain webpages the elements become visible only when you have scrolled through them, in such cases scrolling becomes necessary.

Now, there are multiple ways of scrolling through a webpage, which will be explained here by the means of scroll down method and same can be implemented for scroll up with minimal changes. There are 3 methods for scrolling :-

    Scroll up/down by pixel

executeScript("window.scrollBy(x-pixel,y-pixel)");


The parameters x-pixel, y-pixel here represents the pixels on the screen, x-pixel would move right if the value is negative and vice versa, y-pixel moves up if the value is negative and down if it is more positive.

To scroll up, the pixel could be adjusted to have incremental setup.

    Scroll up/down by the visibility of the element

 js.executeScript("argument[0].scrollIntoView();",Element );


The parameter “argument[0]” here represents first index of that page starting at 0.

    Scroll down to the bottom of page/ up to top of page

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


The parameter "document.body.scrollHeight" here represents the complete height of the webpage.

To Scroll up put    - documnent.body.scrollHeight and to scroll down document.body.scrollHeight.

If you wish to Learn Selenium visit this Selenium Webdriver Tutorial by Intellipaat.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification!

0 votes
by (50.2k points)

For this, there are multiple ways of scrolling through a webpage, which will be explained here by the means of scroll down method and the same can be implemented for scroll up with minimal changes. There are 3 methods for scrolling:-

Scroll up/down by pixel

Scroll up/down by the visibility of the element

Scroll down to the bottom of page/ up to top of page

As all the details are mentioned perfectly by shivangi go through that to resolve the issue.

I would like to give you a small sort of demo regarding this selenium web driver

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...