Search code examples
rubyseleniumwebdriverwatir

Ruby/Watir disable Save password prompt


This question relates to automation testing in chrome using Rubymine, Watir and Selenium. How do we disable this from popping up in Chrome

enter image description here

These are our current options for chromedriver

options = Selenium::WebDriver::Chrome::Options.new(
      options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
      args: ["ignore-certificate-errors", "disable-infobars"]
  )
  options.add_preference(:credentials_enable_service, false)
  options.add_preference(:password_manager_enabled, false)
  driver = Selenium::WebDriver.for :chrome, options: options

Solution

  • Using Preferences

    You are setting the preferences correctly. The problem is that you're running into a bug in Selenium-WebDriver - https://github.com/SeleniumHQ/selenium/issues/7917.

    Until the fix is released, you'll need to use Strings for the preferences instead of Symbols:

    options.add_preference("credentials_enable_service", false)
    options.add_preference("password_manager_enabled", false)
    

    Note that you don not need to create the Selenium Options directly. You can let Watir do this for you:

    browser = Watir::Browser.new(
      :chrome,
      options: {
        options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
        args: ["ignore-certificate-errors", "disable-infobars", '--disable-features=RendererCodeIntegrity'],
        prefs: {"credentials_enable_service" => false, "password_manager_enabled" => false}
      }
    )
    

    Using Incognito

    Alternatively, instead of setting preferences, you could use incognito mode:

    options = Selenium::WebDriver::Chrome::Options.new(
      options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
      args: ["incognito", "ignore-certificate-errors", "disable-infobars"]
    )