diff --git a/lib/webrat/core/elements/label.rb b/lib/webrat/core/elements/label.rb index 9e7f29b..3f8388b 100644 --- a/lib/webrat/core/elements/label.rb +++ b/lib/webrat/core/elements/label.rb @@ -23,7 +23,7 @@ module Webrat if for_id.blank? Webrat::XML.xpath_at(@element, *Field.xpath_search) else - Webrat::XML.css_search(@session.dom, "#" + for_id).first + Webrat::XML.css_search(@session.current_dom, "#" + for_id).first end end diff --git a/spec/public/within_spec.rb b/spec/public/within_spec.rb index a65cc34..a0e40ec 100644 --- a/spec/public/within_spec.rb +++ b/spec/public/within_spec.rb @@ -123,6 +123,27 @@ describe "within" do click_button "Add" end end + + it "should not find fields outside of the scope" do + with_html <<-HTML + +
+ + + HTML + + webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com") + within "#form2" do + fill_in "Email", :with => "test@example.com" + click_button "Add" + end + end it "should not find buttons outside of the scope" do with_html <<-HTML