每次我的 webdriver 测试登录到应用程序时,都会弹出“您希望 chrome 保存您的密码”。有没有办法避免这种情况?
请帮忙。
谢谢,迈克
每次我的 webdriver 测试登录到应用程序时,都会弹出“您希望 chrome 保存您的密码”。有没有办法避免这种情况?
请帮忙。
谢谢,迈克
您需要配置以下 chrome 驱动程序选项:
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
}
我正在使用 Python,这对我有用:
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')
只需将这些首选项添加到您的 chrome 驱动程序选项中:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
是的,我刚刚找到了答案。我不得不查看 Chrome 的用户数据目录并找到所有可用的 chromeOptions Preferences 文件。我在 Centos 7 上,所以路径如下所示:
~/.config/google-chrome/Default/Preferences
为了删除保存密码对话框,配置 JSON chromeOptions 部分需要有这个:
chromeOptions: {
prefs: {
profile: {
password_manager_enabled: false
}
}
}
终于找到了这些选项真的让我很高兴,但是,令人失望的是 google 或 selenium 没有列出所有可配置的首选项。
感谢上面的@karanvir Kang 评论,我在我调用量角器时使用的 conf.js 中添加了以下内容。例子
protractor tests/conf.js --specs /tests/e2e/myspec.spec.js
在我的 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'
]
}
},
您还可以在隐身模式下启动 chromedriver 以阻止信息栏出现。请注意,体验将类似于隐身模式。命令将是
chrome.exe --incognito
如果您从命令行运行,则可以添加--incognito
到 chromeswitch 数组以从 webdriver 执行。
为了提供更完整的图片,这是 Selenium 网格中 Watir 的工作配置:
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
在 github 上的 docker-grid-watir上查看完整的概念证明。
我知道这已经很老了,它已经得到了正确的回答。只是想给我的5美分。如果您使用的是 Robot Framework,下面是这样做的方法。
open-browser
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
${cred_dict}= Create Dictionary credentials_enable_service=${FALSE}
Call Method ${chrome_options} add_experimental_option prefs ${cred_dict}
Create Webdriver Chrome chrome chrome_options=${chrome_options}