首页 > 解决方案 > Selenium IE11 警报弹出句柄不适用于关闭浏览器弹出窗口

问题描述

问题: 我将 IE11 与 Selenium Webdriver 一起使用,当我尝试关闭 IE 浏览器时,我得到一个“来自网页的消息”弹出显示,我试图单击“确定”但警报句柄不起作用,它没有单击“好的”。

Selenium 版本:3.12.0 IEDriverServer(32 位)版本:3.12.0

public void selectReqFolder() throws Exception {

    windowHandle = new WindowsHandle();
    //Clicking here open new child window 
    driver.findElement(Contract_File_Action_Copy_Frwd_Trnsction_button_Solcitation_Link).click();
    //Window handle method, switch focus on to child window and does all the task in there
    windowHandle.windowsHandle();
    //Using window handles to switch to parent window
    Set<String> s1 = driver.getWindowHandles();
    // Now we will iterate using Iterator to go over the totoal windows
    Iterator<String> I1 = s1.iterator();
    // List of the windows
    String parent = I1.next();
    String child_window = I1.next();
    **[![// Here we will compare if parent window 
    driver.switchTo().window(parent);
    //Closing the broswer
            driver.close();
        Thread.sleep(4000);
         //Handeling Alert
         Alert alert = driver.switchTo().alert();
        // Capturing alert message.    
        String alertMessage= driver.switchTo().alert().getText();   
        //To click on OK button of the alert
         driver.switchTo().alert().accept();][1]][1]**
        }

在此处输入图像描述

标签: seleniumselenium-webdriverinternet-explorer-11selenium-iedriver

解决方案


推荐阅读