那麼,您需要使用自定義配置來初始化ChromeDriver,該配置將禁用標誌來阻止彈出窗口。在這個網站上,它的命令行開關是禁用彈出式窗口。因此,使用ChromeOptions和DesiredCapabilities,您可以使用DesiredCapabilities.setCapability()函數添加所需的配置。
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
編輯:剛剛發現本網站上的同一個解決方案。
還有另一個選項來啓用彈出窗口。因爲有時您的公司可能會阻止您以管理員模式訪問任何應用程序。如果上述方法失效,您可以使用以下代碼啓用彈出窗口。
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("chrome://settings/content");
Thread.sleep(4000);
driver.switchTo().frame("settings");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@type='radio' and @name='popups']")).click();
Thread.sleep(4000);
driver.findElement(By.id("content-settings-overlay-confirm"));
Thread.sleep(4000);
Use the above code before starting your test.
來源
2016-08-18 11:17:05
Eby
嗨,你想做什麼?請寫清楚。我的理解中有這種情況。 1)阻止下載彈出(自動下載指定文件夾)2)當您下載內容時,彈出一些彈出窗口3)系統顯示彈出窗口,當您下載任何內容時。你的場景是哪個? – Sagar007
嘗試'chromeCapabilities.setCapability(「enable-download-notification」,false);' – JRodDynamite
更新Chrome驅動程序後得到解決方案 –