123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Chromium::Options

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Selenium::WebDriver::Options
Defined in: rb/lib/selenium/webdriver/chromium/options.rb

Constant Summary

  • CAPABILITIES = # File 'rb/lib/selenium/webdriver/chromium/options.rb', line 27
    {args: 'args',
    binary: 'binary',
    local_state: 'localState',
    prefs: 'prefs',
    detach: 'detach',
    debugger_address: 'debuggerAddress',
    exclude_switches: 'excludeSwitches',
    minidump_path: 'minidumpPath',
    emulation: 'mobileEmulation',
    perf_logging_prefs: 'perfLoggingPrefs',
    window_types: 'windowTypes',
    android_package: 'androidPackage',
    android_activity: 'androidActivity',
    android_device_serial: 'androidDeviceSerial',
    android_use_running_app: 'androidUseRunningApp'}.freeze

::Selenium::WebDriver::Options - Inherited

GRID_OPTIONS, W3C_OPTIONS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

::Selenium::WebDriver::Options - Inherited

Instance Method Summary

::Selenium::WebDriver::Options - Inherited

Constructor Details

.new(profile: nil, **opts) ⇒ Options

Create a new Options instance.

Examples:

options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized', 'user-data-dir=/tmp/temp_profile'])
driver = Selenium::WebDriver.for(:chrome, options: options)

Parameters:

Options Hash (**opts):

  • encoded_extensions (Array)

    List of extensions that do not need to be Base64 encoded

  • args (Array<String>)

    List of command-line arguments to use when starting ::Selenium::WebDriver::Chrome

  • binary (String)

    Path to the ::Selenium::WebDriver::Chrome executable to use

  • prefs (Hash)

    A hash with each entry consisting of the name of the preference and its value

  • extensions (Array<String>)

    A list of paths to (.crx) ::Selenium::WebDriver::Chrome extensions to install on startup

  • options (Hash)

    A hash for raw options

  • emulation (Hash)

    A hash for raw emulation options

  • local_state (Hash)

    A hash for the Local State file in the user data folder

  • detach (Boolean)

    whether browser is closed when the driver is sent the quit command

  • debugger_address (String)

    address of a ::Selenium::WebDriver::Chrome debugger server to connect to

  • exclude_switches (Array<String>)

    command line switches to exclude

  • minidump_path (String)

    Directory to store ::Selenium::WebDriver::Chrome minidumps (linux only)

  • perf_logging_prefs (Hash)

    A hash for performance logging preferences

  • window_types (Array<String>)

    A list of window types to appear in the list of window handles

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 70

def initialize(profile: nil, **opts)
  super(**opts)

  @profile = profile

  @options = {args: [],
              prefs: {},
              emulation: {},
              extensions: [],
              local_state: {},
              exclude_switches: [],
              perf_logging_prefs: {},
              window_types: []}.merge(@options)

  @logging_prefs = options.delete(:logging_prefs) || {}
  @encoded_extensions = @options.delete(:encoded_extensions) || []
  @extensions = []
  @options.delete(:extensions).each { |ext| validate_extension(ext) }
end

Instance Attribute Details

#extensions (rw)

NOTE: special handling of ‘extensions’ to validate when set instead of when used

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 44

attr_reader :extensions

#extensions=(extensions) (rw)

Add an extension by local path.

Examples:

extensions = ['/path/to/extension.crx', '/path/to/other.crx']
options = Selenium::WebDriver::Chrome::Options.new
options.extensions = extensions

Parameters:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 115

def extensions=(extensions)
  extensions.each { |ext| validate_extension(ext) }
end

#logging_prefs (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 24

attr_accessor :profile, :logging_prefs

#profile (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 24

attr_accessor :profile, :logging_prefs

Instance Method Details

#add_argument(arg)

Add a command-line argument to use when starting ::Selenium::WebDriver::Chrome.

Examples:

Start Chrome maximized

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('start-maximized')

Parameters:

  • arg (String)

    The command-line argument to add

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 143

def add_argument(arg)
  @options[:args] << arg
end

#add_emulation(**opts)

Add emulation device information

see: chromedriver.chromium.org/mobile-emulation

Examples:

Start Chrome in mobile emulation mode by device name

options = Selenium::WebDriver::Chrome::Options.new
options.add_emulation(device_name: 'iPhone 6')

Start Chrome in mobile emulation mode by device metrics

options = Selenium::WebDriver::Chrome::Options.new
options.add_emulation(device_metrics: {width: 400, height: 800, pixelRatio: 1, touch: true})

Parameters:

  • opts (Hash)

    the pre-defined options for adding mobile emulation values

Options Hash (**opts):

  • :device_name (String)

    A valid device name from the ::Selenium::WebDriver::Chrome DevTools Emulation panel

  • :device_metrics (Hash)

    Hash containing width, height, pixelRatio, touch

  • :user_agent (String)

    Full user agent

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 181

def add_emulation(**opts)
  @options[:emulation] = opts
end

#add_encoded_extension(encoded)

Add an extension by Base64-encoded string.

Examples:

options = Selenium::WebDriver::Chrome::Options.new
options.add_encoded_extension(encoded_string)

Parameters:

  • encoded (String)

    The Base64-encoded string of the .crx file

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 129

def add_encoded_extension(encoded)
  @encoded_extensions << encoded
end

#add_extension(path)

Add an extension by local path.

Examples:

options = Selenium::WebDriver::Chrome::Options.new
options.add_extension('/path/to/extension.crx')

Parameters:

  • path (String)

    The local path to the .crx file

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 100

def add_extension(path)
  validate_extension(path)
end

#add_preference(name, value)

Add a preference that is only applied to the user profile in use.

Examples:

Set the default homepage

options = Selenium::WebDriver::Chrome::Options.new
options.add_preference('homepage', 'http://www.seleniumhq.com/')

Parameters:

  • name (String)

    Key of the preference

  • value (Boolean, String, Integer)

    Value of the preference

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 158

def add_preference(name, value)
  @options[:prefs][name] = value
end

#enable_android(package: 'com.android.chrome', serial_number: nil, use_running_app: nil, activity: nil)

Enables mobile browser use on Android.

Parameters:

See Also:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/options.rb', line 197

def enable_android(package: 'com.android.chrome', serial_number: nil, use_running_app: nil, activity: nil)
  @options[:android_package] = package
  @options[:android_activity] = activity unless activity.nil?
  @options[:android_device_serial] = serial_number unless serial_number.nil?
  @options[:android_use_running_app] = use_running_app unless use_running_app.nil?
end