diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index fec866f..7332330 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -60,6 +60,7 @@ describe Capybara::Session do Hello UTF8文字列 + Link HTML [200, @@ -84,6 +85,13 @@ describe Capybara::Session do it "can click utf8 string" do subject.click_button('ボタン') end + + it "raises an ElementNotFound error when the selector scope is no longer valid" do + subject.within('//body') do + subject.click_link 'Link' + lambda { subject.find('//strong') }.should raise_error(Capybara::ElementNotFound) + end + end end context "response headers with status code" do diff --git a/src/capybara.js b/src/capybara.js index 8393225..b52f498 100644 --- a/src/capybara.js +++ b/src/capybara.js @@ -51,7 +51,8 @@ Capybara = { }, isAttached: function(index) { - return document.evaluate("ancestor-or-self::html", this.nodes[index], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue != null; + return this.nodes[index] && + document.evaluate("ancestor-or-self::html", this.nodes[index], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue != null; }, text: function (index) {