Professional Documents
Culture Documents
org.openqa.selenium.JavascriptExecutor;
org.openqa.selenium.WebDriver;
org.openqa.selenium.firefox.FirefoxDriver;
org.testng.annotations.BeforeTest;
org.testng.annotations.Test;
will
return
window
height
window
width
driver.manage().window().getSize().getHeight()
Bellow
given
syntax
using getSize().getWidth().
will
return
driver.manage().window().getSize().getWidth()
org.openqa.selenium.Dimension;
org.openqa.selenium.Point;
org.openqa.selenium.WebDriver;
org.openqa.selenium.firefox.FirefoxDriver;
org.testng.annotations.BeforeTest;
org.testng.annotations.Test;
java.util.concurrent.TimeUnit;
org.openqa.selenium.Dimension;
org.openqa.selenium.JavascriptExecutor;
org.openqa.selenium.WebDriver;
org.openqa.selenium.firefox.FirefoxDriver;
org.testng.annotations.BeforeTest;
org.testng.annotations.Test;
driver.manage().window().setSize(new Dimension(400,400));
//Check and print horizontal and vertical scroll status.
checkAndPrintScrollStatus();
Thread.sleep(2000);
//resize window to remove horizontal scroll from page.
driver.manage().window().setSize(new Dimension(1024,400));
//Check and print horizontal and vertical scroll status.
checkAndPrintScrollStatus();
}
public void checkAndPrintScrollStatus(){
JavascriptExecutor javascript = (JavascriptExecutor) driver;
//Check If horizontal scroll Is present or not.
Boolean b1 = (Boolean) javascript.executeScript("return
document.documentElement.scrollWidth>document.documentElement.clientWidth;");
//Check If vertical scroll Is present or not.
Boolean b2 = (Boolean) javascript.executeScript("return
document.documentElement.scrollHeight>document.documentElement.clientHeight;")
;
if (b1 == true && b2 == true) {
System.out.println("Horizontal and vertical Scrollbar is present on
page.");
} else if (b1 == false && b2 == true) {
System.out.println("Horizontal Scrollbar not present on page.");
System.out.println("Vertical Scrollbar is present on page.");
}else if (b1 == true && b2 == false) {
System.out.println("Horizontal Scrollbar Is present on page.");
System.out.println("Vertical Scrollbar not present on page.");
}else if (b1 == false && b2 == false) {
System.out.println("Horizontal and Vertical Scrollbar not present on
page.");
}
System.out.println("<----------x--------x--------->");
}
}