Reputation: 3283
Is it even possible ? I currently have :
require 'selenium-webdriver'
phantomjs_useragent = {"phantomjs.page.settings.userAgent" => "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"}
driver = Selenium::WebDriver.for :phantomjs
driver.capabilities.merge!(phantomjs_useragent)
driver.navigate.to "http://whatsmyuseragent.com/"
puts driver.first(:tag_name => 'body').text
That gets me, which is not the user agent I put in :
Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.8.1 Safari/534.34
Upvotes: 2
Views: 4433
Reputation: 11756
According to this suggestion:
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Custom Agent/1.0")
Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
Was merged for selenium-webdriver-2.31 and later
Upvotes: 4