For Scroll down:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
or
jse.executeScript("scroll(0, 250);");
For Scroll up:
jse.executeScript("window.scrollBy(0,-250)", "");
OR,
jse.executeScript("scroll(0, -250);");
Other Examples:
Scrolling to bottom of a page
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
Scrolling to specific element of a page
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", WebElement);
Scrolling by co-ordinates of a page
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
scrolling up without using JavascriptExecutor.executeScript() function
String mvScrollBar = Keys.chord(Keys.CONTROL, Keys.HOME);
driver.findElement(By.xpath("xpath expression")).sendKeys(mvScrollBar);
Desired Capabilities:
The desired capability is a series of key/value pairs that stores the browser properties like browsername, browser version, the path of the browser driver in the system, etc.
to determine the behaviour of the browser at run time.
Desired capability can also be used to configure the driver instance of Selenium WebDriver.
We can configure driver instance like FirefoxDriver, ChromeDriver, InternetExplorerDriver by using desired capabilities.
Example:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE");
capabilities.setPlatform(Platform.WIN8_1);
WebDriver driver = newInternetExplorerDriver(capabilities);
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
or
jse.executeScript("scroll(0, 250);");
For Scroll up:
jse.executeScript("window.scrollBy(0,-250)", "");
OR,
jse.executeScript("scroll(0, -250);");
Other Examples:
Scrolling to bottom of a page
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
Scrolling to specific element of a page
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", WebElement);
Scrolling by co-ordinates of a page
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
scrolling up without using JavascriptExecutor.executeScript() function
String mvScrollBar = Keys.chord(Keys.CONTROL, Keys.HOME);
driver.findElement(By.xpath("xpath expression")).sendKeys(mvScrollBar);
Desired Capabilities:
The desired capability is a series of key/value pairs that stores the browser properties like browsername, browser version, the path of the browser driver in the system, etc.
to determine the behaviour of the browser at run time.
Desired capability can also be used to configure the driver instance of Selenium WebDriver.
We can configure driver instance like FirefoxDriver, ChromeDriver, InternetExplorerDriver by using desired capabilities.
Example:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE");
capabilities.setPlatform(Platform.WIN8_1);
WebDriver driver = newInternetExplorerDriver(capabilities);