title: Watir - Handling a new window
body: <p>I'm trying to have a very simple script with Watir, and for some reason can't:</p>
  
  <p>This should login to a website with Twitter.</p>
  
  <pre><code>browser = Watir::Browser.start 'http://www.12mass.com/'
  browser.link(:class, 'priceLogin').click
  sleep 2
  browser.element(:class, 'loginTwitter').click
  browser.windows.last.use do
          browser.text_field(:id, 'username_or_email').click
          browser.text_field(:id, 'username_or_email').set 'name'
          browser.text_field(:id, 'password').set 'pass'
  
          browser.button(:id, 'allow').click
      end
  </code></pre>
  
  <p>I get to a point where a new window opens, but I can't reach it and fill the credentials... </p>
  
  <p>Every now an then I get an error (in my log): `rescue in rbuf_fill'.
  I already added:</p>
  
  <pre><code>require 'net/http' 
  http = Net::HTTP.new(@host, @port)
  http.read_timeout = 500
  </code></pre>
  
  <p>To my code, but I still get the error and can't log fill the credentials in the new window.</p>
  
  <p>Also, I tried this:</p>
  
  <pre><code>browser.windows.last.use
  browser.element(:css, '[for="username_or_email"]').click
  </code></pre>
  
  <p>Had the same error..</p>