title: Capture screenshot of alert
body: <p>I have used the below code to take screenshot of the application after pop up appears. </p>
  
  <pre class="lang-java prettyprint-override"><code>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();
  </code></pre>
  
  <p>But it is throwing this exception </p>
  
  <blockquote>
    <p>Exception in thread "main" org.openqa.selenium.UnhandledAlertException:Modal dialog present: Assessment Name already Exist.</p>
  </blockquote>
  
  <p>But the code works fine if I remove the screenshot procedures.</p>