Search code examples
rubyseleniumselenium-webdriverwatir

How to create chrome profile via Ruby Selenium Binding(or WATIR)


I know how to create profile for Firefox

require 'watir'
options = Selenium::WebDriver::Firefox::Options.new
options.profile = "default"
@driver = Selenium::WebDriver.for :firefox, options: options
@b = Watir::Browser.new @driver

But when I do same thing for Chrome it's not creating, Infact I realized that options(please look above) object doesn't even have the method profile= so I try adding profile like as given below(I saw how people are creating in Java Selenium Binding so I have done the same but it's not working here)

options = Selenium::WebDriver::Firefox::Options.new
options.add_argument('user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default')
@driver = Selenium::WebDriver.for :chrome, options: options

Can someone help me how to create Chrome Profile via Ruby Selenium binding(or WATIR)?


Solution

  • Using an existing or creating a new profile can be done via Chromedrivers user-data-dir argument. In Watir, you can pass the argument via the :args parameter:

    browser = Watir::Browser.new :chrome, 
      args: ['user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data']
    

    Note that if you trying to use the existing default profile, you do not want to include the "Default" directory in the path.