java - 如何在 Selenium 中禁用保存密码弹出窗口?

标签 java selenium selenium-chromedriver selenium-firefoxdriver

我正在使用适用于 Java 的 Selenium 版本 3.141.59,我想在初始化 Chrome 和 Firefox 驱动程序时禁用密码弹出窗口。

我正在使用选项语法,因为 DesiredCapativity 替代方案现已弃用。我的代码看起来像这样,但它不起作用:

  • 火狐浏览器
FirefoxOptions options = new FirefoxOptions();
options.addPreference("signon.rememberSignons", false);
webDriver = new FirefoxDriver(options);
  • Chrome
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("credentials_enable_service", false);
chromeOptions.setExperimentalOption("profile.password_manager_enabled", false);
webDriver = new ChromeDriver(chromeOptions);

如何在创建驱动程序之前将该选项添加到选项对象?

最佳答案

下面是java代码,对我有用。我将 selenium 3.3.1 与 selenium-chrome-driver 3.3.1 和 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);

关于java - 如何在 Selenium 中禁用保存密码弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56311000/

相关文章:

java - Xpath 选择器在 IE 中不起作用,但在 Chrome 和 Firefox 中工作正常

java - JScrollPane 不会更新 JSplitPane 上的 JScrollBar

java - 如何扩展 Spring Web 服务?

java - Maven 阴影 : include only specific artifacts and exclude all the rest

java - Gson将float解析为int

java - 如何在java selenium中根据样式属性进行点击

google-chrome - 如何使用 webdriver 和 Chrome 在本地主机上可靠地设置 cookie?

python - 在 Selenium 中处理弹出窗口

c# - 如何在 IWebDriver 中使用 IE 选项?

selenium-chromedriver - 使用 Chrome 驱动程序的 C# Selenium 代理身份验证