From 58c5b413397113fb744d2fe901d83294e1a0328c Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Tue, 2 Apr 2013 19:25:26 -0400 Subject: [PATCH] Don't look for attached nodes at invalid indices --- spec/integration/session_spec.rb | 8 ++++++++ src/capybara.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) 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) {