Scroll Commands | Java Selenium WebDriver

One of the most important things that any Automation Developer wants to know about Web Automations,is how to Execute Web Scrolling. in the following blog , i will show you exactly how :)

1.define “Javascript Executor” driver

for Executing Web Scrolling,we will define our “Javascript Executor” driver.

2.Navigating to “YouTube” Website

to Execute Our scrolling,let’s open “YouTube” Website.

3.Maximize Web View

This command will maximize the Web View.

4.put Thread.sleep command

This command will put some hold (sleep) between each upcoming steps

5.Mark all current steps

Long press on your Right click (Mouse),and mark all current steps.

6.Surrounding steps with try/catch Function

To make sure our steps are safe,we will surround them with try/catch function,that will help us to prevent Expections.to have the option available,click CTRL + ALT + t

7.Finish Surrounding

This is how your steps should be look,after you surround them with try/catch

8.Execute Scrolling (down)

And now,let’s Execute our Scrolling down in the current Web View.

the values in the .executeScript command will define how long the scroll is going to be. in this example,we put 0 (for up scroll),and 400 for down scroll.

9.Scrolling back (Up)

And now,let’s scroll back (up) for the beginning of the page.

for back scrolling (up),we just need to put the same value as we put in the first scrolling,but just to add “-” before the value.

And now we’re back again in the top of the Website (YouTube).

Very important to put Thread.sleep command before each scrolling Execution,to make sure nothing goes wrong.

That’s all for now,hope you enjoy :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.