title: capybara - Find with xPath is leaving the within scope
body: <p>I am trying to build a date selector with Capybara using the default Rails date, time, and datetime fields. I am using the <code>within</code> method to find the select boxes for the field but when I use xPath to find the correct box it leaves the <code>within</code> scope and find the first occurrence on the page of the element.</p>
  
  <p>Here is the code I am using. The page I am testing on has 2 datetime fields but I can only get it to change the first because of this error. At the moment I have an div container with id that wraps up the datetime field but I do plan on switching the code to find by the label.</p>
  
  <pre><code>module  Marketron
    module DateTime
  
      def select_date(field, options = {})
        date_parse = Date.parse(options[:with])
  
        year = date_parse.year.to_s
        month = date_parse.strftime('%B')
        day = date_parse.day.to_s
  
        within("div##{field}") do
          find(:xpath, "//select[contains(@id, \"_#{FIELDS[:year]}\")]").select(year)
          find(:xpath, "//select[contains(@id, \"_#{FIELDS[:month]}\")]").select(month)
          find(:xpath, "//select[contains(@id, \"_#{FIELDS[:day]}\")]").select(day)
        end
  
      end
  
      def select_time(field, options = {})
        require "time"
        time_parse = Time.parse(options[:with])
  
        hour = time_parse.hour.to_s.rjust(2, '0')
        minute = time_parse.min.to_s.rjust(2, '0')
  
        within("div##{field}") do
          find(:xpath, "//select[contains(@id, \"_#{FIELDS[:hour]}\")]").find(:xpath, "option[contains(@value, '#{hour}')]").select_option
          find(:xpath, "//select[contains(@id, \"_#{FIELDS[:minute]}\")]").find(:xpath, "option[contains(@value, '#{minute}')]").select_option
  
        end
  
      end
  
      def select_datetime(field, options = {})
        select_date(field, options)
        select_time(field, options)
      end
  
      private
  
        FIELDS = {year: "1i", month: "2i", day: "3i", hour: "4i", minute: "5i"}
  
    end
  end
  
  World(Marketron::DateTime)
  </code></pre>