Alert 在 seleniumn 中弹出屏幕截图

问题描述 投票:0回答:0

你好,我正在使用 seleniumn 4.8.0 执行一个 Web 自动化脚本,但我无法捕获警报弹出窗口的屏幕截图,我遇到了异常,有什么方法可以捕获警报弹出窗口屏幕截图,我尝试了以下方法,但没有成功

  1. AShot 库
  2. 机器人类捕获屏幕截图,但如果我们最小化浏览器,它将捕获该屏幕截图

我需要在 selenium grid arciteure 和 Edge 上使用 IE 兼容模式的建议

公共类 AlertPopUp {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.setProperty("webdriver.chrome.driver", "D:\\AlertPopUp\\chromedriver_win32 (2)\\chromedriver.exe");

    RemoteWebDriver driver = new ChromeDriver();

    try {
        driver.get("file:///D:/AlertPopUp/alertPopup.html");
        Thread.sleep(500);
        driver.manage().window().maximize();
        driver.findElement(By.xpath("(//button[text()='Try it'])")).click();
        driver.switchTo().alert();
        // screenShotsPopUp(driver);
        Thread.sleep(5000);
        System.out.println("after sleep");
        screenShotsPopUp(driver);
        Thread.sleep(5000);
        driver.quit();

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

}


public static void screenShotsPopUp(RemoteWebDriver driver) {

    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
    try {
        ImageIO.write(screenshot.getImage(), "PNG", new File("D:\\AlertPopUp\\fullPage.png"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

selenium-chromedriver selenium-grid selenium-iedriver ashot
© www.soinside.com 2019 - 2024. All rights reserved.