9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/webdriver-user-agent-randomizer.rb', line 9
def self.driver options={}
options[:browser] ||= :firefox
user_agent = ua_pool[Random.rand(ua_pool.size)]
case options[:browser]
when :firefox
options[:profile] ||= Selenium::WebDriver::Firefox::Profile.new
options[:profile]['general.useragent.override'] = user_agent
when :chrome
options[:switches] ||= []
options[:switches] << "--user-agent=#{user_agent}"
else
raise "WebDriver UserAgent currently only supports :firefox and :chrome."
end
driver = Selenium::WebDriver.for options[:browser], options.except(:browser)
driver
end
|