问题描述
我正在为 Java 使用 Selenium 版本 3.141.59,我想在初始化 Chrome 和 Firefox 的驱动程序时禁用密码弹出.
I am using Selenium version 3.141.59 for Java and I would like to disable password popup while initializing the driver for Chrome and Firefox.
我正在使用 Options 语法,因为 DesiredCapabilities 替代方案现已弃用.我的代码看起来像这样,但它不起作用:
I am using the Options syntax since the DesiredCapabilities alternative is now deprecated. My code look like this, but it is not working:
- 火狐
FirefoxOptions options = new FirefoxOptions();
options.addPreference("signon.rememberSignons", false);
webDriver = new FirefoxDriver(options);
- 铬
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("credentials_enable_service", false);
chromeOptions.setExperimentalOption("profile.password_manager_enabled", false);
webDriver = new ChromeDriver(chromeOptions);
如何在创建驱动程序之前将该选项添加到选项对象?
How can I add that option to the options object before creating the driver?
推荐答案
下面是java代码,对我有用.我将 selenium 3.3.1 与 selenium-chrome-driver 3.3.1 和 Java 8 一起使用.
Below are java code, which worked for me. I am using selenium 3.3.1 with selenium-chrome-driver 3.3.1 and Java 8.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--no-proxy-server");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
这篇关于如何禁用 Selenium 中的保存密码弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!