Selenium webdriver Selenium Webdriver运行时异常:意外警报“;请关闭应用程序的其他打开选项卡,然后重新打开此活动“;

Selenium webdriver Selenium Webdriver运行时异常:意外警报“;请关闭应用程序的其他打开选项卡,然后重新打开此活动“;,selenium-webdriver,Selenium Webdriver,Selenium Webdriver运行时异常:意外警报“请关闭应用程序的其他打开的选项卡并重新打开此活动”,即使没有其他选项卡打开。 自动化脚本工作正常,但最近我遇到了上述异常。警报的屏幕截图: 我尝试使用不同版本的chrome、selenium独立驱动程序,但问题仍然存在。为什么会出现此警报,即使应用程序未在任何选项卡或浏览器中打开(通过联机执行的除外)?如果每次都在某个特定位置出现此弹出窗口,则您只需写下以下几行即可接受此警报: WebDriver wb=new ChromeDriver

Selenium Webdriver运行时异常:意外警报“请关闭应用程序的其他打开的选项卡并重新打开此活动”,即使没有其他选项卡打开。 自动化脚本工作正常,但最近我遇到了上述异常。警报的屏幕截图:


我尝试使用不同版本的chrome、selenium独立驱动程序,但问题仍然存在。为什么会出现此警报,即使应用程序未在任何选项卡或浏览器中打开(通过联机执行的除外)?

如果每次都在某个特定位置出现此弹出窗口,则您只需写下以下几行即可接受此警报:

WebDriver wb=new ChromeDriver();
wb.switchTo().alert().accept();
否则,如果在初始化驱动程序时出现任何意外的弹出窗口,则可以使用以下代码:

ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
String path=new GetBasePath().getPath_XML()+dir;
prefs.put("download.default_directory", path);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false); 
options.setExperimentalOption("prefs", prefs);

options.addArguments("chrome.switches","--disable-extensions");

options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",**path to chromedriver.exe**"));
WebDriver wb= new ChromeDriver(cap);
ChromeOptions选项=新的ChromeOptions();
Map prefs=新的HashMap();
prefs.put(“profile.default\u content\u settings.popups”,0);
字符串路径=新的GetBasePath().getPath_XML()+dir;
prefs.put(“下载.默认目录”,路径);
options.addArguments(“禁用扩展”);
prefs.put(“凭证启用服务”,false);
prefs.put(“密码管理器已启用”,false);
选项。设置实验选项(“prefs”,prefs);
options.addArguments(“chrome.switches”,“--禁用扩展”);
options.addArguments(“--test type”);
DesiredCapabilities=DesiredCapabilities.chrome();
上限设置能力(色度选项、能力、选项);
cap.setCapability(CapabilityType.UNEXPECTED\u ALERT\u行为,UNEXPECTED AlertBehaviour.ACCEPT);
System.setProperty(“webdriver.chrome.driver”,指向chromedriver.exe的路径**”);
WebDriver wb=新的色度驱动程序(cap);
我个人的意见,两者都用。

如果你觉得这个(或任何)答案有帮助,请投上一票。如果这个答案回答了你的问题,请将其标记为已接受的答案。谢谢!