123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Firefox::Options

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

Constant Summary

::Selenium::WebDriver::Options - Inherited

GRID_OPTIONS, W3C_OPTIONS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

::Selenium::WebDriver::Options - Inherited

Instance Method Summary

Constructor Details

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

Create a new Options instance, only for W3C-capable versions of ::Selenium::WebDriver::Firefox.

Examples:

options = Selenium::WebDriver::Firefox::Options.new(args: ['--host=127.0.0.1'])
driver = Selenium::WebDriver.for :firefox, options: options

Parameters:

  • opts (Hash)

    the pre-defined options to create the Options with

Options Hash (**opts):

  • :binary (String)

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

  • :args (Array<String>)

    List of command-line arguments to use when starting geckodriver

  • :profile (Profile, String)

    Encoded profile string or Profile instance

  • :log_level (String, Symbol)

    Log level for geckodriver

  • :prefs (Hash)

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

  • :options (Hash)

    A hash for raw options

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 59

def initialize(log_level: nil, **opts)
  @debugger_address = opts.delete(:debugger_address) { true }
  opts[:accept_insecure_certs] = true unless opts.key?(:accept_insecure_certs)

  super(**opts)

  @options[:args] ||= []
  @options[:prefs] ||= {}
  # Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it.
  # https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/.
  @options[:prefs]['remote.active-protocols'] = 3
  @options[:env] ||= {}
  @options[:log] ||= {level: log_level} if log_level

  process_profile(@options.delete(:profile))
end

Instance Attribute Details

#debugger_address (rw)

[ GitHub ]

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

attr_accessor :debugger_address

#log_level (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 124

def log_level
  @options.dig(:log, :level)
end

#log_level=(level) (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 128

def log_level=(level)
  @options[:log] = {level: level}
end

#profile (rw)

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

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 41

attr_reader :profile

#profile=(profile) (rw)

Sets Firefox profile.

Examples:

Set the custom profile

profile = Selenium::WebDriver::Firefox::Profile.new
options = Selenium::WebDriver::Firefox::Options.new
options.profile = profile

Use existing profile

options = Selenium::WebDriver::Firefox::Options.new
options.profile = 'myprofile'

Parameters:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 120

def profile=(profile)
  process_profile(profile)
end

Instance Method Details

#add_argument(arg)

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

Examples:

Start geckodriver on a specific host

options = Selenium::WebDriver::Firefox::Options.new
options.add_argument('--host=127.0.0.1')

Parameters:

  • arg (String)

    The command-line argument to add

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 86

def add_argument(arg)
  @options[:args] << arg
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::Firefox::Options.new
options.add_preference('browser.startup.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/firefox/options.rb', line 101

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

#camelize?(key) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 171

def camelize?(key)
  key != 'prefs'
end

#enable_android(package: 'org.mozilla.firefox', serial_number: nil, activity: nil, intent_arguments: nil)

Enables mobile browser use on Android.

Parameters:

  • package (String)

    The package name of the ::Selenium::WebDriver::Chrome or WebView app.

  • serial_number (String)

    The serial number of the device on which to launch the application. If not specified and multiple devices are attached, an error will be returned.

  • activity (String)

    The fully qualified class name of the activity to be launched.

  • intent_arguments (Array)

    Arguments to launch the intent with.

See Also:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 144

def enable_android(package: 'org.mozilla.firefox', serial_number: nil, activity: nil, intent_arguments: nil)
  @options[:android_package] = package
  @options[:android_activity] = activity unless activity.nil?
  @options[:android_device_serial] = serial_number unless serial_number.nil?
  @options[:android_intent_arguments] = intent_arguments unless intent_arguments.nil?
end

#process_browser_options(browser_options) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 153

def process_browser_options(browser_options)
  browser_options['moz:debuggerAddress'] = true if @debugger_address
  options = browser_options[KEY]
  options['binary'] ||= Firefox.path if Firefox.path
  options['profile'] = @profile if @profile
end

#process_profile(profile) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/firefox/options.rb', line 160

def process_profile(profile)
  @profile = case profile
             when nil
               nil
             when Profile
               profile
             else
               Profile.from_name(profile)
             end
end