Question: I have used the below code to take screenshot of the application after pop up appears. 

```java
Alert alert = driver.switchTo().alert();
File scrFile= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("G:\\Screens\\sc1.jpg"));
String alertMsg = alert.getText();
System.out.println(alertMsg);
alert.accept();

```

But it is throwing this exception 

> 
> Exception in thread "main" org.openqa.selenium.UnhandledAlertException:Modal dialog present: Assessment Name already Exist.
> 
> 
> 

But the code works fine if I remove the screenshot procedures.

Answer: 
You have to handle the alert before you take a screenshot... you can read about it more here
<https://code.google.com/p/selenium/issues/detail?id=4412>
You can always get the screenshot of entire page using Robot. I just tried it out, this code is working:

```
WebDriver driver;
@Before
public void init() throws Exception {
    driver = new FirefoxDriver();
    driver.get("http://www.tizag.com/javascriptT/javascriptalert.php");
}

@Test
public void bla() throws AWTException, IOException {
    WebElement element = driver.findElement(By.xpath("//input[@type=\"button\"]"));
    // Trigger the alert
    element.click();
    BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    ImageIO.write(image, "png", new File("c:\\localdev\\bla.png"));
    driver.switchTo().alert().accept();
}

```