I'm new to selenium and JS SweetAlert2. I want to check if the SweetAlert2 is displayed or not. I was able to do so using the isDisplayed()
function. Nonetheless, once the SweetAlert2 is closed, the isDisplayed()
function can't locate it anymore. Thus, I get the following error: No such element: Unable to locate element: ...
.
Below is my code:
boolean actual_SwtAlert = driver.findElement(By.xpath("Rel Xpath Location")).isDisplayed();
boolean expected_SwtAlert = false;
if (actual_SwtAlert == expected_SwtAlert) {
System.out.println("Successfully closed SweetAlert2!");
} else {
System.out.println("Failed to close SweetAlert2!");
}
Assert.assertEquals(actual_SwtAlert, expected_SwtAlert);
How can I do this?