title: Setting custom User Agent in Selenium Webdriver for PhantomJS with Ruby
body: <p>I've been all over the net tonight, for about 3-4 hours now. I've tried every suggestion I've come across. I've even checked the "capabilities" object on my Selenium driver object to ensure that it is actually set there, and indeed, it is:</p>
  
  <pre><code>#&lt;Selenium::WebDriver::Remote::Capabilities:0x00000007475cf0
   @capabilities=
    {:browser_name=&gt;"phantomjs",
     :version=&gt;"1.9.7",
     :platform=&gt;:"linux-unknown-64bit",
     :javascript_enabled=&gt;true,
     :css_selectors_enabled=&gt;true,
     :takes_screenshot=&gt;true,
     :native_events=&gt;true,
     :rotatable=&gt;false,
     :firefox_profile=&gt;nil,
     :proxy=&gt;#&lt;Selenium::WebDriver::Proxy:0x00000007475908 @type=:direct&gt;,
     "driverName"=&gt;"ghostdriver",
     "driverVersion"=&gt;"1.1.0",
     "handlesAlerts"=&gt;false,
     "databaseEnabled"=&gt;false,
     "locationContextEnabled"=&gt;false,
     "applicationCacheEnabled"=&gt;false,
     "browserConnectionEnabled"=&gt;false,
     "webStorageEnabled"=&gt;false,
     "acceptSslCerts"=&gt;false,
     "proxy"=&gt;{"proxyType"=&gt;"direct"},
     "phantomjs.page.settings.userAgent"=&gt;
      "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0"}&gt;
  </code></pre>
  
  <p>Besides "phantomjs.page.settings.userAgent", I've tried "userAgent", etc. Every thing I could find online in the last 3-4 hours, I've tried. Apparently, near the beginning of 2013, this was a quite common question, and the solutions I'm speaking of were apparently the common solutions. None of these are working, and in fact, I know this for sure from this bit of information <strong>(note that User-Agent is "Ruby")</strong>:</p>
  
  <pre><code>UNCAUGHT EXCEPTION: {"errorMessage"=&gt;"Element is not currently visible and may not be manipulated",
   "request"=&gt;
    {"headers"=&gt;
      {"Accept"=&gt;"application/json",
       "Accept-Encoding"=&gt;"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
       "Connection"=&gt;"close",
       "Content-Length"=&gt;"2",
       "Content-Type"=&gt;"application/x-www-form-urlencoded",
       "Host"=&gt;"localhost:9876",
       "User-Agent"=&gt;"Ruby"},
     "httpVersion"=&gt;"1.1",
     "method"=&gt;"POST",
     "post"=&gt;"{}",
     "postRaw"=&gt;"{}",
     "url"=&gt;"/click",
     "urlParsed"=&gt;
      {"anchor"=&gt;"",
       "query"=&gt;"",
       "file"=&gt;"click",
       "directory"=&gt;"/",
       "path"=&gt;"/click",
       "relative"=&gt;"/click",
       "port"=&gt;"",
       "host"=&gt;"",
       "password"=&gt;"",
       "user"=&gt;"",
       "userInfo"=&gt;"",
       "authority"=&gt;"",
       "protocol"=&gt;"",
       "source"=&gt;"/click",
       "queryKey"=&gt;{},
       "chunks"=&gt;["click"]},
     "urlOriginal"=&gt;
      "/session/a03cc440-4f5c-11e4-8854-ed9c22bf60af/element/%3Awdc%3A1412822036214/click"}}
  </code></pre>
  
  <p>Unfortunately, there is a lot more information and discussion on these kinds of Selenium issues, and many others, <em>if</em> you're using Java. At this point, I wish in every way I had gone with Java for this project, but now I have 30,000 lines of code that I wrote entirely myself over the past 2 months. Losing this work, now at least, would not only be devastating for me personally, but would be disastrous for my job.</p>
  
  <p>What gives? Am I really going to have to dig in and customize the source to get what I want, or is this feature <em>really</em> implemented now? Again, I saw all the answers from early 2013, but they don't work for me, and I have no idea why, or how to easily fix it. I'm on a deadline so this is beginning to be very stressful.</p>
  
  <p>Does anyone have any ideas for me? Keep in mind I'm using Ruby, not Java.</p>
  
  <p>Selenium-webdriver is 2.43. PhantomJS is 1.9.7. GhostDriver is 1.1.0.</p>
  
  <p>This seems incredulous, to me, that there is no way to modify your User-Agent.</p>
  
  <p>Please let me know if I can supply any other information that might be of assistance.</p>
  
  <p>I appreciate in advance if you'd be so kind to share a few ideas or some information to get me pointed in the right direction.</p>