[英]Watir: How to set `chrome://settings/content/pdfDocuments`
[英]How to save Chrome's settings when using Watir?
Chrome浏览器正在中断流程,并询问我(用户)是否要允许当前站点发送桌面通知。 我曾尝试在Chrome的“高级设置”页面中更改此设置,但是每次Watir实例化新的浏览器实例时,所有设置都会恢复为默认设置。
除了处理代码来处理这种事情外,我更喜欢使用指定的设置生成一个实例,但是我找不到执行该操作的方法。
任何帮助或有识之士对此深表感谢。
Watir Webdriver 0.9.1
上面的作品,但我发现有时配置文件设置并非总是可以使用。 一种替代方法是使用chrome的命令行开关。
您可以这样添加它们:
b = Watir::Browser.new :chrome, :switches => %w[--disable-notifications]
可以在此处找到所有命令行开关的完整列表。 http://peter.sh/experiments/chromium-command-line-switches/
注意:并非所有这些开关都仍适用于当前版本的chrome。
当您在temp目录中运行Watir测试时,使用默认设置创建了新的空配置文件
/tmp/.com.google.Chrome.couple_random_characters/Default
Firefox的网络驱动程序可以使用您的个人资料:
require 'watir-webdriver'
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
browser = Watir::Browser.new :firefox, :profile => default_profile
Chrome网络驱动程序不具有此功能您可以为您的配置文件夹解析Chrome偏好设置文件( https://www.chromium.org/user-experience/user-data-directory )
在Linux中的Preferences文件路径:
/home/your_name/.config/google-chrome/Default/Preferences
require 'watir-webdriver'
prefs_hash = {
#chrome preference what you need
#for example:
'profile' => {
'default_content_setting_values' => {'automatic_downloads' => 1}
}
}
browser = Watir::Browser.new :chrome, :prefs => prefs_hash
(... chrome偏好设置结构可以更改,而在文档中未描述)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.