問題描述
我正在為 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 中的保存密碼彈出窗口?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!