title: How can I switch between two frames with Capybara
body: <p>I am trying do something inside 2 frames but error raises everytime when I try to switch between frames.
  For example:</p>
  
  <pre><code># encoding: utf-8
  
  require "capybara/dsl"
  
  Capybara.run_server = false
  Capybara.current_driver = :selenium
  Capybara.app_host = 'https://hb.posted.co.rs/posted'
  
  class Account
    include Capybara::DSL
  
    def check_balance
      visit('/')
      page.driver.browser.switch_to.frame 'main'
      fill_in 'korisnik', :with =&gt; 'foo'
      fill_in 'lozinka', :with =&gt; 'bar'
      click_button 'Potvrda unosa'
  
      page.driver.browser.switch_to.frame 'header'
      click_on 'Stanje' 
    end
  end
  
  account = Account.new
  account.check_balance
  </code></pre>
  
  <p>Error is:</p>
  
  <blockquote>
    <p>[remote server]
    file:///tmp/webdriver-profile20120810-9163-xy6dtm/extensions/fxdriver@googlecode.com/components/driver_component.js:6638:in
    `unknown': Unable to locate frame: main
    (Selenium::WebDriver::Error::NoSuchFrameError)</p>
  </blockquote>
  
  <p>What is the problem? Maybe I am doing something wrong here?</p>
  
  <p>If I change order of switching frames so try first to switch to 'header' then switch to 'main' frame then same error raises except that it says that this time there is no 'main' frame:</p>
  
  <pre><code># encoding: utf-8
  
  require "capybara/dsl"
  
  Capybara.run_server = false
  Capybara.current_driver = :selenium
  Capybara.app_host = 'https://hb.posted.co.rs/posted'
  
  class Account
    include Capybara::DSL
  
    def check_balance
      visit('/')
      page.driver.browser.switch_to.frame 'header'
      click_on 'Stanje' 
  
      page.driver.browser.switch_to.frame 'main'
      fill_in 'korisnik', :with =&gt; 'foo'
      fill_in 'lozinka', :with =&gt; 'bar'
      click_button 'Potvrda unosa'
    end
  end
  
  account = Account.new
  account.check_balance
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>[remote server]
    file:///tmp/webdriver-profile20120810-9247-w3o5hj/extensions/fxdriver@googlecode.com/components/driver_component.js:6638:in
    `unknown': Unable to locate frame: main
    (Selenium::WebDriver::Error::NoSuchFrameError)</p>
  </blockquote>