WebDriver Chrome Browser: Avoid 'Do you want chrome to save your password' pop up

[亡魂溺海] 提交于 2019-11-28 11:57:10

You need to configure the following chrome driver options:

chromeOptions: {
            prefs: {
                'credentials_enable_service': false,
                'profile': {
                    'password_manager_enabled': false
                }
            }
        }

I'm using Python, and this worked for me:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option('prefs', {
    'credentials_enable_service': False,
    'profile': {
        'password_manager_enabled': False
    }
})
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://google.com')
Anuj Teotia

Just add these preferences to your chrome driver options:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false); 
options.setExperimentalOption("prefs", prefs);

Yeah I just found the answer. I had to look into the Chrome's user data directory and find all the available chromeOptions the Preferences file. I'm on Centos 7 so the path looks like this:

~/.config/google-chrome/Default/Preferences

In order to remove the save password dialog, the config JSON chromeOptions section needs to have this:

chromeOptions: {
    prefs: {
        profile: {
            password_manager_enabled: false
        }
    }
}

It really makes me happy that I have finally found these options, however, it still is disappointing that google or selenium didn't list all the configurable preferences.

You can also start the chromedriver in incognito mode to stop the infobars from appearing. Please note that the experience will be like the incognito mode. Command will be

chrome.exe --incognito if you are running from command line you can add --incognito to chromeswitch array for executing from webdriver.

Thanks to @karanvir Kang comment above, I added the following to my conf.js which I use when I call protractor. Example

protractor tests/conf.js --specs /tests/e2e/myspec.spec.js

And in my conf.js

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    seleniumPort: '4455',
    baseUrl: url,
    directConnect: false,
    //getMultiCapabilities: helper.getFirefoxProfile,
    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            prefs: {
                'credentials_enable_service': false,
                'profile': {
                    'password_manager_enabled': false
                }
            },
            args: [
                '--disable-cache',
                '--disable-application-cache',
                '--disable-offline-load-stale-cache',
                '--disk-cache-size=0',
                '--v8-cache-options=off'
            ]
        }
    },

To provide a more complete picture, here is a working configuration for Watir in a Selenium Grid:

RSpec.configure do |config|
  config.before :all do
    capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
      chromeOptions: {
          prefs: {
              'credentials_enable_service': false,
              'profile': {
                  'password_manager_enabled': false
              }
          }
      }
    )

    @browser = Watir::Browser.new(
      :remote,
      url: "http://#{ENV.fetch('HUB_HOST')}/wd/hub",
      desired_capabilities: capabilities
    )
  end

  config.after :all do
    @browser&.close
  end
end

See a full proof of concept on github at docker-grid-watir.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!