在使用Selenium和Java运行测试时,每次我登录站点时,我都会得到这个烦人的弹出窗口"您是否希望Chrome保存密码?"。该表可阻止硒正在寻找的东西,因此我的下方元素将找不到,并且测试失败。
我读过,您可以转到高级设置并取消选中我所做的盒子。但是,它仍然显示该窗口弹出窗口。我猜这是因为我们每次都会启动一个新的镀铬,因此Chrome不记得以前的选项。Chrome是通过硒和Java启动的。
有没有某种方法可以在没有密码窗口的情况下启动Chrome?也许是旗帜之类的?
我正在使用Chrome 57.有人得到Chrome 55,并让我使用它,但是Chrome会自动更新,因此将其重置为57。我认为这并不重要吗?
要启动Chrome禁用密码管理器您需要:
-
下载并使用此链接中的最新Chrome驱动程序。
-
添加首选项&代码的选项如下:
System.setProperty("webdriver.chrome.driver", "C:\SeleniumUtilities\BrowserDrivers\chromedriver.exe"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(capabilities); driver.get("http:\gmail.com");
让我知道这是否对您有帮助。
添加以下偏好:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);