Page Scrolling

Scrolling on any web page is required almost always.
You may use below snippets to do scrolling in any direction you need.
JavascriptExecutor jsx = (JavascriptExecutor) driver;

Vertical scroll – down by 100 pixels
jsx.executeScript(“window.scrollBy(0,100)”, “”);

Vertical scroll – up by 55 pixels (note the number is minus 55)
jsx.executeScript(“window.scrollBy(0,-55)”, “”);

Horizontal scroll – right by 20 pixels
jsx.executeScript(“window.scrollBy(20,0)”, “”);

Horizontal scroll – left by 95 pixels (note the number is minus 95)
jsx.executeScript(“window.scrollBy(-95,0)”, “”);
Using Selenium RC1
selenium.getEval(“window.scrollTo(0,0)”);

Using WbdDriver Scroll down:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“window.scrollBy(0,250)”, “”);
or, you can do as follows:
jse.executeScript(“scroll(0, 250);”);

For Scroll up:
jse.executeScript(“window.scrollBy(0,-250)”, “”); OR, jse.executeScript(“scroll(0, -250);”);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s