@naveen, generally it happens with Chrome Browser. ChromeDriver is able to take screen shot of visible part. So the concept here is scroll through the page using Java script executor and take multiple images, then combining them to a single image. FirefoxDriver is able to take image of whole screen without issue. Here is an example
@Test(enabled=true)
public void screenShotExample() throws IOException{
//WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "yourpath to chromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.w3schools.com/");
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
JavascriptExecutor jexec = (JavascriptExecutor)driver;
jexec.executeScript("window.scrollTo(0,0)"); // will scroll to (0,0) position
boolean isScrollBarPresent = (boolean)jexec.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight");
long scrollHeight = (long)jexec.executeScript("return document.documentElement.scrollHeight");
long clientHeight = (long)jexec.executeScript("return document.documentElement.clientHeight");
int fileIndex = 1;
if(driver instanceof ChromeDriver){
if(isScrollBarPresent){
while(scrollHeight > 0){
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
jexec.executeScript("window.scrollTo(0,"+clientHeight*fileIndex++ +")");
scrollHeight = scrollHeight - clientHeight;
}
}else{
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
}
}else{
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
}
// Combine all the .jpg file to single file
driver.close();
driver.quit();
}
To combine all image file you will find some help here. Hope this will help you.