Java – how do I wait for the alert box to perform an action in selenium?

I press the Cancel button than check some text according to my code In chrome and Firefox, it works normally, but in ie, it takes time to perform operations on the alarm box, but the code moves to the next line

So I want some code to stop until the operation is executed in the warning box, and then go to the next step I'm using selenium for automated testing

Please find a code:

Alert al = driver.switchTo().alert();
al.accept();

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='content-body-full']/p[1]")));
assertEquals("Your cancellation request has been successfully executed.",driver.findElement(By.xpath(".//*[@id='content-body-full']/p[1]")).getText().toString());

Solution

You want to wait until the alarm appears before switching to it, similar to line 3 Reference.

Edit: try:

new webdriverwait(driver,60)
        .ignoring(NoAlertPresentException.class)
        .until(ExpectedConditions.alertIsPresent());

Alert al = driver.switchTo().alert();
al.accept();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>