Reputation: 1
I need to capture the full page of IE browser. I am using web driver. Pls help me.
below code is used to capture the present window only.
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
Upvotes: 0
Views: 1431
Reputation: 29
import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
public class TakeScreenshotWithScroll {
static WebDriver driver;
public static void main(String args[]) throws Exception{
String key = "webdriver.gecko.driver";
String value = "driver/geckodriver.exe";
driver = new FirefoxDriver();
System.setProperty(key, value);
driver.get("ENTER THE URL HERE");
Thread.sleep(2000);
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
}
}
Here is the download link of aShot Jar file
Upvotes: 0
Reputation: 600
You can change the browser to full screen before taking the screenshot. This is the code:
private void changeToFullScreen() {
try {
Robot r;
r = new Robot();
r.keyPress(java.awt.event.KeyEvent.VK_F11);
r.keyRelease(java.awt.event.KeyEvent.VK_F11);
driver.sleep(2);
} catch (AWTException e) {
log.error("It was not possible to maximize", e)
driver.manage().window().maximize();
}
}
If you don't want to change the screen size, you can obtain the browser height and take screenShots while you scroll down until the bottom (can be done with Robot):
int numberOfScrolls = pageHeight / browserHeight;
for(int i = 0 ; i < numberOfScrolls ; i++){
takeScreenshot();
scrollDown(browserHeight);
}
concatenateScreenshots();
Upvotes: 1