简体   繁体   中英

How to save Chrome's settings when using Watir?

Chrome is interrupting the flow and asking about whether I (the user) want to allow desktop notifications to be sent by the current site. I've tried changing this in the Advanced Settings page of Chrome, but each time Watir instantiates a new browser instance all the settings are back to the default.

Instead of dealing with code to handle this kind of thing, I'd much prefer to spawn an instance with settings I've specified but I can't find how to do this.

Any help or insight with this is much appreciated.

Watir Webdriver 0.9.1

The above works but I have found that sometimes profile settings are not always picked up. An alternative is to use chrome's command line switches.

You can add them like so:

b = Watir::Browser.new :chrome, :switches => %w[--disable-notifications]

A full list of all command line switches can be found here. http://peter.sh/experiments/chromium-command-line-switches/

To note: Not all of these switches still work with the current version of chrome.

when you run Watir test in temp directory created new empty profile with default settings

/tmp/.com.google.Chrome.couple_random_characters/Default

web-driver for Firefox can use you profile:

require 'watir-webdriver'

default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
browser = Watir::Browser.new :firefox, :profile => default_profile

Chrome web-driver not have this functionality You can parse Chrome preference file for you config folder ( https://www.chromium.org/user-experience/user-data-directory )

in Linux path to Preferences file:

/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 preference structure can be changed and not describe in documentation)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM