繁体   English   中英

如何解决Internet Explorer和Selenium中的“出现的模式对话框:如果离开此页面,任何更改都会丢失”?

[英]How to solve “Modal dialog present: If you leave this page, any changes will be lost” in internet explorer and selenium?

以下是我的代码。 下面的代码能够删除警报框,但在控制台中会引发错误

线程“主”中的异常org.openqa.selenium.UnhandledAlertException:存在模态对话框:如果离开此页面,任何更改都将丢失。 内部版本信息:版本:“ 3.0.1”,修订版:“ 1969d75”,时间:“ 2016-10-18 09:48:19 -0700”“”我正在使用Internet Explorer 11

driver.findElement(By.xpath("//div[@id=ctl02_cp1_ucGI")).click();

Thread.sleep(4000);
if (ExpectedConditions.alertIsPresent() != null)
{
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.onbeforeunload = function() {};"); 
    System.out.println("alert is present");
}
else
{
    System.out.println("alert is not present");
}

Thread.sleep(4000);
WebElement product1=driver.findElement(By.xpath("//select[@id='ctl00_cp1_ucGI_ddlProduct']"));

您可以尝试通过硒接受警报

public void checkAlert() 
{
    try 
    {
        // Wait for the alert is present
        WebDriverWait wait = new WebDriverWait(driver, 2);
        wait.until(ExpectedConditions.alertIsPresent());

        // Switch to the alert
        Alert alert = driver.switchTo().alert();

        // Close the alert
        alert.accept();
    } 
    catch (Exception e) 
    {
        //exception handling
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM