如何禁用Selenium中的保存密码弹出窗口?

时间:2019-05-26 05:49:30

标签: java selenium selenium-chromedriver selenium-firefoxdriver

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

由于DesiredCapabilities替代选项现在已被弃用,因此我正在使用Options语法。我的代码如下所示,但无法正常工作:

  • Firefox
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);

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

2 个答案:

答案 0 :(得分:1)

如果我正确理解您是指chrome中的内置密码管理器。您可以执行以下操作以禁用它而不使用所需的功能:

  1. 点击工具栏中的Chrome菜单Chrome菜单图标。
  2. 选择“设置”
  3. 在顶部的搜索栏中输入“密码”。
  4. 选择“自动填充”。
  5. 关闭以下“保存密码的要约”和“自动登录”。

在开始执行测试之前,此步骤被认为包括在环境设置过程中。 另外,我想向您强调,大多数浏览器在自动化模式下使用时都将其关闭。因此,我认为您可能应该选择更新浏览器版本作为更好的选择。

答案 1 :(得分:0)

下面是对我有用的Java代码。我正在使用selenium 3.3.1和selenium-chrome-driver 3.3.1和Java 8。

            Glide.with(mContext)
                    .load(mImageUrl)
                    .apply(new RequestOptions()
                                         .placeholder(R.drawable.home_placeholder)
                            .error(R.drawable.home_placeholder)
                            .fallback(R.drawable.home_placeholder)
                            .format(DecodeFormat.PREFER_ARGB_8888)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                           )
                    .thumbnail(0.1f)
                    .into(cardView.getMainImageView());