How to handle below Internet Explorer popup “Are you sure you want to leave this page?” through Selenium

前端 未结 2 1121
遇见更好的自我
遇见更好的自我 2020-12-21 23:34

How to Handle below IE Popup in Selenium

\"enter

2条回答
  •  清酒与你
    2020-12-22 00:04

    You can try to accept the alert via selenium. Not sure what language you're using but the following Java method should accept the alert and let you move on with your life.

    public void checkAlert() 
    {
        try 
        {
            // Wait for the alert to show
            WebDriverWait wait = new WebDriverWait(driver, 2);
            wait.until(ExpectedConditions.alertIsPresent());
    
            driver.switchTo().alert().accept();
    
        } 
        catch (Exception e) 
        {
            //exception handling
        }
    }
    

    You'll want to add import org.openqa.selenium.Alert; to your imports (again if you're using Java)

提交回复
热议问题