How to capture alert screenshot in Selenium WebDriver 4.7.2, Java 17

138 Views Asked by At

Selenium tests unable to capture screenshot when alert is raised.

I set the desired capability too.

chromeOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, "ignore");

But the script failing at 2nd line. Tried applying explicit waits too but no use.

driverManager.getWebDriver().switchTo().alert();
byte[] screenshot = ((TakesScreenshot) driverManager.getWebDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "attachment-"+LocalTime.now().toSecondOfDay());
driverManager.getWebDriver().switchTo().defaultContent();

Other stack overflow articles doesn't seem to help. Is there any solution for this? Are there any popular 3rd party libraries can be used for this purpose?

0

There are 0 best solutions below