You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Capybara+Selenium环境下配置Chrome禁用「保存卡片」弹窗?

禁用Chrome「保存卡片?」弹窗的Capybara+Selenium配置

要关闭Chrome在自动化测试中弹出的「保存卡片?」对话框,只需在Chrome选项中添加对应的偏好设置即可,完整代码示例如下:

browser_options = ::Selenium::WebDriver::Options.chrome
# 针对性禁用支付类自动填充提示(含保存卡片弹窗)
browser_options.add_preference('payment_autofill_enabled', false)
# 可选:彻底禁用所有自动填充提示
# browser_options.add_preference('autofill.profile_enabled', false)
# browser_options.add_preference('profile.default_content_setting_values.autofill', 2)
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)

参数说明:

  • payment_autofill_enabled: 直接关闭支付相关的自动填充功能,包括触发「保存卡片?」的弹窗逻辑
  • autofill.profile_enabled: 禁用Chrome的自动填充用户配置文件,从根源上减少各类自动填充提示
  • profile.default_content_setting_values.autofill: 将自动填充的内容权限设为「阻止」(2代表阻止,1为允许,0为默认)

一般情况下,仅设置payment_autofill_enabled: false就足以解决保存卡片弹窗的问题;如果还有其他自动填充提示干扰测试,可以搭配另外两个参数使用。

内容的提问来源于stack exchange,提问作者Eliot Sykes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 20:30:00