Created
May 1, 2013 18:28
-
-
Save tehprofessor/5497198 to your computer and use it in GitHub Desktop.
Configuring Watir to use a custom user agent with the PhantomJS driver. The user agent gem has been deprecated, and this functionality is not documented anywhere (obvious).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'watir-webdriver' | |
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36") | |
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities | |
browser = ::Watir::Browser.new driver | |
# Quick test to make sure it's set | |
browser.goto 'http://www.useragentstring.com/' | |
browser.textarea(:id => "uas_textfeld").value | |
# => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we update the
:desired_capabilities
on the fly, I mean after we initialize the browser object ?