如果彈出在某些特定位置,每次來了,那麼你可以簡單地通過編寫以下行接受它:
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);
我的個人意見,同時使用。
如果您發現這個(或任何)答案有幫助,請注意它。如果這回答了您的問題,請將其標記爲已接受的答案。謝謝! –