title: Opening a new tab in Capybara / Poltergeist
body: <p>I'm trying to open a link by clicking on it using capybara/poltergeist which opens up in a new tab. </p>
  
  <p>I can't seem to get it working. </p>
  
  <pre><code>@session.find(&lt;link&gt;).click
  </code></pre>
  
  <p>just seems to stay on the same page, as does </p>
  
  <pre><code>click_link "&lt;link&gt;"
  
  @session.driver.window_handles 
  </code></pre>
  
  <p>Only seems to give me 1 window whatever I'm doing. </p>
  
  <p>How do I get that link to open in a new tab?</p>
  
  <p>Seems to be a fair amount of confusion as to what works or doesn't a la (<a href="https://stackoverflow.com/questions/7612038/with-capybara-how-do-i-switch-to-the-new-window-for-links-with-blank-targets">With Capybara, how do I switch to the new window for links with &quot;_blank&quot; targets?</a>). </p>
  
  <p>Hoping somebody has worked it out... Can't seem to get my head around it.</p>
  
  <p>Ok. By updating to the latest version of poltergeist (1.6.0) we have some progress. </p>
  
  <p>Now however I have two windows but no idea how to switch between them.</p>
  
  <pre><code>@session.windows
  </code></pre>
  
  <p>gives me </p>
  
  <p>[Window @handle="0", Window @handle="1"]
  (slightly modified as it was going a bit funny).</p>
  
  <p>But </p>
  
  <pre><code>@session.switch_to_window(1)
  </code></pre>
  
  <p>results in </p>
  
  <pre><code>NoMethodError: undefined method `handle' for "1":String
  </code></pre>