title: Error while switching windows using Selenium Webdriver
body: <p>I've written a Ruby script to automate some user operations using IE. 
  I'm using Selenium Web Driver for IE. Below is my code.</p>
  
  <pre><code>require 'selenium-webdriver'
  
  browser = Selenium::WebDriver.for :ie
  
  first_window = browser.window_handle
  browser.switch_to.frame(browser.find_element(:id=&gt; 'outerFrame'))
  browser.switch_to.frame(browser.find_element(:id=&gt; 'innerFrame'))
  
  table_rows = browser.find_element(:id=&gt; 'AllItems').find_element(:tag_name=&gt; 'table').find_elements(:tag_name=&gt; 'tr')
  count_cell = table_rows.at(table_rows.length-1).find_elements(:tag_name=&gt; 'td').at(1).find_element(:tag_name=&gt; 'a')
  count_cell.click
  
  sleep(5)
  
  all_windows = browser.window_handles
  new_window = browser.window_handles.last
  
  browser.switch_to.window(new_window)
  
  btn = browser.find_element(:id=&gt; 'btn_export')
  btn.click
  </code></pre>
  
  <p>At one point, after clicking a button, a new page is opened. Now, when I try to switch to the new window, I get the following error.</p>
  
  <blockquote>
    <p>C:/Ruby21/lib/ruby/2.1.0/net/http.rb:879:in 'initialize': No
    connection could be made because the target machine actively refused
    it. - connect(2) for "127.0.0.1" port 5555 (Errno::ECONNREFUSED)
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:879:in 'open'
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:879:in 'block in connect'
            from C:/Ruby21/lib/ruby/2.1.0/timeout.rb:75:in 'timeout'
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:878:in 'connect'
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:863:in 'do_start'
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:852:in 'start'
            from C:/Ruby21/lib/ruby/2.1.0/net/http.rb:1375:in 'request'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/http/default.rb:107:in 'response_for'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/http/default.rb:58:in
    'request'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/http/common.rb:59:in
    'call'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/bridge.rb:664:in
    'raw_execute'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/bridge.rb:642:in
    'execute'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/remote/bridge.rb:216:in
    'switchToWindow'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.48.1/lib/selenium/webdriver/common/target_locator.rb:81:in
    'window'
            from script.rb:18:in ''</p>
  </blockquote>
  
  <p>I tried my bit to resolve the error, by modifying firewall and added rules for port 5555. Even then issue persists. I found some already exsting questions on this, but most of them are related to Java or .Net. How can I resolve this error? Can anyone point me in the right direction?</p>