![](/img/trans.png)
[英]Allure generates a viewport screenshot. how to capture a screenshot of the entire document
[英]Capture screenshot of alert
弹出后,我使用下面的代码截取应用程序的屏幕截图。
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();
但它正在抛出这个例外
线程“main”中的异常org.openqa.selenium.UnhandledAlertException:存在模式对话框:评估名称已存在。
但是如果删除屏幕截图程序,代码工作正常。
您必须在截取屏幕截图之前处理警报...您可以在此处阅读更多信息https://code.google.com/p/selenium/issues/detail?id=4412
您始终可以使用Robot获取整个页面的屏幕截图。 我刚试了一下,这段代码正在运行:
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.