Javascript 如何处理以下Internet Explorer弹出窗口“;您确定要离开此页吗?“;通过硒
如何在Selenium中处理下面的IE弹出窗口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接受警报。不确定您使用的是哪种语言,但下面的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如果此/任何答案对您有帮助,对未来的读者有帮助,请回答。您能为我提供解决方案吗?这是一样的,对吗?只需切换到警报并接受它。如果你愿意,我可以在上面加上答案。