How to use extensions method of Selenium.WebDriver.Chrome Package

Best Selenium code snippet using Selenium.WebDriver.Chrome.extensions

options.rb

Source:options.rb Github

copy

Full Screen

...17module Selenium18 module WebDriver19 module Chrome20 class Options21 attr_reader :args, :prefs, :options, :emulation, :extensions, :encoded_extensions22 attr_accessor :binary23 KEY = 'goog:chromeOptions'.freeze24 #25 # Create a new Options instance.26 #27 # @example28 # options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized', 'user-data-dir=/tmp/temp_profile'])29 # driver = Selenium::WebDriver.for(:chrome, options: options)30 #31 # @param [Hash] opts the pre-defined options to create the Chrome::Options with32 # @option opts [Array<String>] :args List of command-line arguments to use when starting Chrome33 # @option opts [String] :binary Path to the Chrome executable to use34 # @option opts [Hash] :prefs A hash with each entry consisting of the name of the preference and its value35 # @option opts [Array<String>] :extensions A list of paths to (.crx) Chrome extensions to install on startup36 # @option opts [Hash] :options A hash for raw options37 # @option opts [Hash] :emulation A hash for raw emulation options38 #39 def initialize(**opts)40 @args = Set.new(opts.delete(:args) || [])41 @binary = opts.delete(:binary) || Chrome.path42 @prefs = opts.delete(:prefs) || {}43 @extensions = opts.delete(:extensions) || []44 @options = opts.delete(:options) || {}45 @emulation = opts.delete(:emulation) || {}46 @encoded_extensions = []47 end48 #49 # Add an extension by local path.50 #51 # @example52 # options = Selenium::WebDriver::Chrome::Options.new53 # options.add_extension('/path/to/extension.crx')54 #55 # @param [String] path The local path to the .crx file56 #57 def add_extension(path)58 raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)59 raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'60 @extensions << path61 end62 #63 # Add an extension by Base64-encoded string.64 #65 # @example66 # options = Selenium::WebDriver::Chrome::Options.new67 # options.add_encoded_extension(encoded_string)68 #69 # @param [String] encoded The Base64-encoded string of the .crx file70 #71 def add_encoded_extension(encoded)72 @encoded_extensions << encoded73 end74 #75 # Add a command-line argument to use when starting Chrome.76 #77 # @example Start Chrome maximized78 # options = Selenium::WebDriver::Chrome::Options.new79 # options.add_argument('start-maximized')80 #81 # @param [String] arg The command-line argument to add82 #83 def add_argument(arg)84 @args << arg85 end86 #87 # Add a new option not yet handled by bindings.88 #89 # @example Leave Chrome open when chromedriver is killed90 # options = Selenium::WebDriver::Chrome::Options.new91 # options.add_option(:detach, true)92 #93 # @param [String, Symbol] name Name of the option94 # @param [Boolean, String, Integer] value Value of the option95 #96 def add_option(name, value)97 @options[name] = value98 end99 #100 # Add a preference that is only applied to the user profile in use.101 #102 # @example Set the default homepage103 # options = Selenium::WebDriver::Chrome::Options.new104 # options.add_preference('homepage', 'http://www.seleniumhq.com/')105 #106 # @param [String] name Key of the preference107 # @param [Boolean, String, Integer] value Value of the preference108 #109 def add_preference(name, value)110 prefs[name] = value111 end112 #113 # Run Chrome in headless mode.114 #115 # @example Enable headless mode116 # options = Selenium::WebDriver::Chrome::Options.new117 # options.headless!118 #119 def headless!120 add_argument '--headless'121 # https://bugs.chromium.org/p/chromium/issues/detail?id=737678#c1122 add_argument '--disable-gpu' if WebDriver::Platform.windows?123 end124 #125 # Add an emulation device name126 #127 # @example Start Chrome in mobile emulation mode by device name128 # options = Selenium::WebDriver::Chrome::Options.new129 # options.add_emulation(device_name: 'iPhone 6')130 #131 # @example Start Chrome in mobile emulation mode by device metrics132 # options = Selenium::WebDriver::Chrome::Options.new133 # options.add_emulation(device_metrics: {width: 400, height: 800, pixelRatio: 1, touch: true})134 #135 # @param [String] device_name Name of the device or a hash containing width, height, pixelRatio, touch136 # @param [Hash] device_metrics Hash containing width, height, pixelRatio, touch137 # @param [String] user_agent Full user agent138 #139 def add_emulation(device_name: nil, device_metrics: nil, user_agent: nil)140 @emulation[:deviceName] = device_name if device_name141 @emulation[:deviceMetrics] = device_metrics if device_metrics142 @emulation[:userAgent] = user_agent if user_agent143 end144 #145 # @api private146 #147 def as_json(*)148 extensions = @extensions.map do |crx_path|149 File.open(crx_path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }150 end151 extensions.concat(@encoded_extensions)152 opts = @options153 opts[:binary] = @binary if @binary154 opts[:args] = @args.to_a if @args.any?155 opts[:extensions] = extensions if extensions.any?156 opts[:mobileEmulation] = @emulation unless @emulation.empty?157 opts[:prefs] = @prefs unless @prefs.empty?158 {KEY => opts}159 end160 end # Options161 end # Chrome162 end # WebDriver163end # Selenium...

Full Screen

Full Screen

driver.rb

Source:driver.rb Github

copy

Full Screen

...65 profile = profile.as_json66 if options.args.none?(&/user-data-dir/.method(:match?))67 options.add_argument("--user-data-dir=#{profile['directory']}")68 end69 if profile['extensions']70 WebDriver.logger.deprecate 'Selenium::WebDriver::Chrome::Profile#extensions',71 'Selenium::WebDriver::Chrome::Options#add_extension'72 profile['extensions'].each do |extension|73 options.add_encoded_extension(extension)74 end75 end76 end77 if opts.key?(:detach)78 WebDriver.logger.deprecate 'Selenium::WebDriver::Chrome::Driver#new with `:detach` parameter',79 'Selenium::WebDriver::Chrome::Options#new or Options#add_option'80 options.add_option(:detach, opts.delete(:detach))81 end82 prefs = opts.delete(:prefs)83 if prefs84 WebDriver.logger.deprecate ':prefs', 'Selenium::WebDriver::Chrome::Options#add_preference'85 prefs.each do |key, value|86 options.add_preference(key, value)...

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1options.add_argument('--headless')2options.add_argument('--disable-gpu')3options.add_argument('--window-size=1280x1696')4options.add_argument('--user-data-dir=/tmp/user-data')5options.add_argument('--hide-scrollbars')6options.add_argument('--enable-logging')7options.add_argument('--log-level=0')8options.add_argument('--v=99')9options.add_argument('--single-process')10options.add_argument('--data-path=/tmp/data-path')11options.add_argument('--ignore-certificate-errors')12options.add_argument('--homedir=/tmp')13options.add_argument('--disk-cache-dir=/tmp/cache-dir')14options.add_argument('--media-cache-dir=/tmp/media-cache-dir')15options.add_argument('--disable-default-apps')16options.add_argument('--no-first-run')17options.add_argument('--no-sandbox')18options.add_argument('--disable-dev-shm-usage')19options.add_argument('--remote-debugging-port=9222')20caps = Selenium::WebDriver::Remote::Capabilities.chrome(21options.add_argument('--headless')22options.add_argument('--disable-gpu')23options.add_argument('--window-size=1280x1696')24options.add_argument('--user-data-dir=/tmp/user-data')25options.add_argument('--hide-scrollbars')26options.add_argument('--enable-logging')27options.add_argument('--log-level=0')28options.add_argument('--v=99')29options.add_argument('--single-process')30options.add_argument('--data-path=/tmp/data-path')31options.add_argument('--ignore-certificate-errors')32options.add_argument('--homedir=/tmp')33options.add_argument('--disk-cache-dir=/tmp/cache-dir')34options.add_argument('--media-cache-dir=/tmp/media-cache-dir')

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1driver.manage.add_cookie(name: 'name', value: 'value')2driver.manage.add_cookie(name: 'name', value: 'value')3driver.manage.add_cookie(name: 'name', value: 'value')4driver.manage.add_cookie(name: 'name', value: 'value')5driver.manage.add_cookie(name: 'name', value: 'value')6driver.manage.add_cookie(name: 'name', value: 'value')7driver.manage.add_cookie(name: 'name',

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1extension_path = File.expand_path(File.dirname(__FILE__))2extension = Selenium::WebDriver::Chrome::Extension.new(extension_path)3launcher = Selenium::WebDriver::Chrome::Launcher.new(chrome_path, :port => 9515)4service = Selenium::WebDriver::Chrome::Service.new(:port => 9515)5driver.extensions.load(extension)6driver.execute_script('window.open()')7driver.switch_to.window(driver.window_handles.last)

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1 def add_extension (path)2 def add_extension (path)3 def add_extension (path)4 def add_extension (path)

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1Selenium::WebDriver::Chrome::Service.driver_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"2caps = Selenium::WebDriver::Remote::Capabilities.chrome(3 chromeOptions: { args: [ "--start-maximized" ] }4Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }5browser.button(:name => 'btnI').click6Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1options.add_argument('--headless')2options.add_argument('--disable-gpu')3options.add_argument('--window-size=1280x1696')4options.add_argument('--user-data-dir=/tmp/user-data')5options.add_argument('--hide-scrollbars')6options.add_argument('--enable-logging')7options.add_argument('--log-level=0')8options.add_argument('--v=99')9options.add_argument('--single-process')10options.add_argument('--data-path=/tmp/data-path')11options.add_argument('--ignore-certificate-errors')12options.add_argument('--homedir=/tmp')13options.add_argument('--disk-cache-dir=/tmp/cache-dir')14options.add_argument('--media-cache-dir=/tmp/media-cache-dir')15options.add_argument('--disable-default-apps')16options.add_argument('--no-first-run')17options.add_argument('--no-sandbox')18options.add_argument('--disable-dev-shm-usage')19options.add_argument('--remote-debugging-port=9222')20caps = Selenium::WebDriver::Remote::Capabilities.chrome(21options.add_argument('--headless')22options.add_argument('--disable-gpu')23options.add_argument('--window-size=1280x1696')24options.add_argument('--user-data-dir=/tmp/user-data')25options.add_argument('--hide-scrollbars')26options.add_argument('--enable-logging')27options.add_argument('--log-level=0')28options.add_argument('--v=99')29options.add_argument('--single-process')30options.add_argument('--data-path=/tmp/data-path')31options.add_argument('--ignore-certificate-errors')32options.add_argument('--homedir=/tmp')33options.add_argument('--disk-cache-dir=/tmp/cache-dir')34options.add_argument('--media-cache-dir=/tmp/media-cache-dir')

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1driver.manage.add_cookie(name: 'name', value: 'value')2driver.manage.add_cookie(name: 'name', value: 'value')3driver.manage.add_cookie(name: 'name', value: 'value')4driver.manage.add_cookie(name: 'name', value: 'value')5driver.manage.add_cookie(name: 'name', value: 'value')6driver.manage.add_cookie(name: 'name', value: 'value')7driver.manage.add_cookie(name: 'name',

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1 def add_extension (path)2 def add_extension (path)3 def add_extension (path)4 def add_extension (path)

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1Selenium::WebDriver::Chrome::Service.driver_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"2caps = Selenium::WebDriver::Remote::Capabilities.chrome(3 chromeOptions: { args: [ "--start-maximized" ] }4Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }5browser.button(:name => 'btnI').click6Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1options.add_argument('--headless')2options.add_argument('--disable-gpu')3options.add_argument('--window-size=1280x1696')4options.add_argument('--user-data-dir=/tmp/user-data')5options.add_argument('--hide-scrollbars')6options.add_argument('--enable-logging')7options.add_argument('--log-level=0')8options.add_argument('--v=99')9options.add_argument('--single-process')10options.add_argument('--data-path=/tmp/data-path')11options.add_argument('--ignore-certificate-errors')12options.add_argument('--homedir=/tmp')13options.add_argument('--disk-cache-dir=/tmp/cache-dir')14options.add_argument('--media-cache-dir=/tmp/media-cache-dir')15options.add_argument('--disable-default-apps')16options.add_argument('--no-first-run')17options.add_argument('--no-sandbox')18options.add_argument('--disable-dev-shm-usage')19options.add_argument('--remote-debugging-port=9222')20caps = Selenium::WebDriver::Remote::Capabilities.chrome(21options.add_argument('--headless')22options.add_argument('--disable-gpu')23options.add_argument('--window-size=1280x1696')24options.add_argument('--user-data-dir=/tmp/user-data')25options.add_argument('--hide-scrollbars')26options.add_argument('--enable-logging')27options.add_argument('--log-level=0')28options.add_argument('--v=99')29options.add_argument('--single-process')30options.add_argument('--data-path=/tmp/data-path')31options.add_argument('--ignore-certificate-errors')32options.add_argument('--homedir=/tmp')33options.add_argument('--disk-cache-dir=/tmp/cache-dir')34options.add_argument('--media-cache-dir=/tmp/media-cache-dir')

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1driver.manage.add_cookie(name: 'name', value: 'value')2driver.manage.add_cookie(name: 'name', value: 'value')3driver.manage.add_cookie(name: 'name', value: 'value')4driver.manage.add_cookie(name: 'name', value: 'value')5driver.manage.add_cookie(name: 'name', value: 'value')6driver.manage.add_cookie(name: 'name', value: 'value')7driver.manage.add_cookie(name: 'name',

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1 def add_extension (path)2 def add_extension (path)3 def add_extension (path)4 def add_extension (path)

Full Screen

Full Screen

extensions

Using AI Code Generation

copy

Full Screen

1Selenium::WebDriver::Chrome::Service.driver_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"2caps = Selenium::WebDriver::Remote::Capabilities.chrome(3 chromeOptions: { args: [ "--start-maximized" ] }4Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }5browser.button(:name => 'btnI').click6Watir::Wait.until { browser.text.include? "I'm Feeling Lucky" }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful