Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何处理以下Internet Explorer弹出窗口“;您确定要离开此页吗?“;通过硒_Javascript_Java_Selenium_Internet Explorer_Onbeforeunload - Fatal编程技术网

Javascript 如何处理以下Internet Explorer弹出窗口“;您确定要离开此页吗?“;通过硒

Javascript 如何处理以下Internet Explorer弹出窗口“;您确定要离开此页吗?“;通过硒,javascript,java,selenium,internet-explorer,onbeforeunload,Javascript,Java,Selenium,Internet Explorer,Onbeforeunload,如何在Selenium中处理下面的IE弹出窗口 您可以尝试通过selenium接受警报。不确定您使用的是哪种语言,但下面的Java方法应该接受这个警告,让您继续生活 public void checkAlert() { try { // Wait for the alert to show WebDriverWait wait = new WebDriverWait(driver, 2); wait.until(Expected

如何在Selenium中处理下面的IE弹出窗口


您可以尝试通过selenium接受警报。不确定您使用的是哪种语言,但下面的Java方法应该接受这个警告,让您继续生活

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
    }
}
您需要添加
import org.openqa.selenium.Alert导入(如果使用Java,同样如此)

文本为的Internet Explorer弹出窗口是否确实要离开此页面?
WindowEventHandlers.onbeforeunload的结果


在卸载之前 mixin的属性是用于处理事件的。当窗口即将释放其资源时,将触发这些事件。此时,文档仍然可见,事件仍然可以取消


解决方案 有不同的策略可用于处理此弹出窗口。但是,作为跨浏览器解决方案,您可以禁用此对话框,调用
executeScript()
窗口设置为
函数(){},您可以使用以下解决方案:

((JavascriptExecutor)driver).executeScript("window.onbeforeunload = function() {};");
您可以在中找到相关的讨论


您可以使用robot类来处理此弹出窗口-有关详细信息,请参阅该链接。@SaravananSeenivasan如果此/任何答案对您有帮助,对未来的读者有帮助,请回答。您能为我提供解决方案吗?这是一样的,对吗?只需切换到警报并接受它。如果你愿意,我可以在上面加上答案。