Selenium IE11警报弹出句柄不适用于关闭浏览器弹出窗口

Selenium IE11警报弹出句柄不适用于关闭浏览器弹出窗口,selenium,selenium-webdriver,internet-explorer-11,selenium-iedriver,Selenium,Selenium Webdriver,Internet Explorer 11,Selenium Iedriver,问题: 我正在将IE11与Selenium Webdriver一起使用,当我尝试关闭IE浏览器时,我会看到一个“Message From WebPage”(来自网页的消息)弹出显示,我尝试单击“OK”(确定),但警报句柄不起作用,它不会单击“OK”(确定) Selenium版本:3.12.0 IEDriverServer(32位)版本:3.12.0 public void selectReqFolder() throws Exception { windowHandle = new W

问题: 我正在将IE11与Selenium Webdriver一起使用,当我尝试关闭IE浏览器时,我会看到一个“Message From WebPage”(来自网页的消息)弹出显示,我尝试单击“OK”(确定),但警报句柄不起作用,它不会单击“OK”(确定)

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]**
        }
public void selectReqFolder()引发异常{
windowHandle=新的WindowsHandle();
//单击此处打开新的子窗口
driver.findElement(合同\文件\操作\复制\文件\操作\按钮\解决方案\链接)。单击();
//窗口句柄方法,将焦点切换到子窗口并在其中执行所有任务
windowHandle.windowshhandle();
//使用窗口句柄切换到父窗口
Set s1=driver.getWindowHandles();
//现在,我们将使用迭代器进行迭代,遍历整个窗口
迭代器I1=s1.Iterator();
//窗口列表
字符串parent=I1.next();
字符串child_window=I1.next();
**[![//这里我们将比较是否为父窗口
driver.switchTo()窗口(父窗口);
//关闭broswer
driver.close();
睡眠(4000);
//利手警戒
Alert Alert=驱动程序.switchTo().Alert();
//捕获警报消息。
String alertMessage=driver.switchTo().alert().getText();
//单击警报的“确定”按钮
driver.switchTo().alert().accept();][1][1]**
}

我会在关闭前导航到另一页。。。然后在切换到ExpectedConditions.alertIsPresent()之前使用它。该driver.close()调用可能会阻止您切换到调用。我猜您还必须处理driver.get()超时。它最终会抛出这个,因为警报会阻止它。此提示来自onunload处理程序。(或在卸载之前)
driver.close()
表示关闭webdriver。我认为这就是为什么不能执行accept alert选项的原因。你可以接受@pcalkins的建议,然后再试一次。你也可以参考。我会在关闭前导航到另一个页面。。。然后在切换到ExpectedConditions.alertIsPresent()之前使用它。该driver.close()调用可能会阻止您切换到调用。我猜您还必须处理driver.get()超时。它最终会抛出这个,因为警报会阻止它。此提示来自onunload处理程序。(或在卸载之前)
driver.close()
表示关闭webdriver。我认为这就是为什么不能执行accept alert选项的原因。你可以接受@pcalkins的建议,然后再试一次。你也可以参考。