Disable Chrome "Save Card?" popup with Capybara

103 views Asked by At

What argument or preference do you configure Chrome with, when using Capybara and Selenium, to disable this "Save card?" dialog?

Save Card popup in Chrome browser

browser_options = ::Selenium::WebDriver::Options.chrome
browser_options.add_preference <WHAT GOES HERE?>
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
1

There are 1 answers

0
Eliot Sykes On

The preference for the "Save card?" behavior is autofill.credit_card_enabled.

To disable it:

Capybara.register_driver :selenium_chrome do |app|
  browser_options = ::Selenium::WebDriver::Options.chrome

  # Disable "Save card?" popup:
  browser_options.add_preference :autofill, credit_card_enabled: false
  # This also works:
  # browser_options.add_preference 'autofill.credit_card_enabled', false
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

To discover the names of preferences like these in Chrome:

  1. Set and save the preference to the value you desire in the UI in chrome://settings
  2. Go to chrome://version/ and note the "Profile Path"
  3. Open the Preferences file found below the "Profile Path". This is a JSON file.
  4. Search this file for a string that looks like it would correspond to the preference you set in step 1. For example "autofill":{"credit_card_enabled":false, is the string I found when researching this answer. You can derive the preference name and value from this, e.g. autofill.credit_card_enabled=false.