mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Handle case where element has gone away while building path
This commit is contained in:
parent
fd6b247f64
commit
6215e5592f
2 changed files with 26 additions and 5 deletions
|
@ -181,7 +181,9 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
when 1
|
when 1
|
||||||
'' # index not necessary when only one matching element
|
'' # index not necessary when only one matching element
|
||||||
else
|
else
|
||||||
"[#{siblings.index(node) + 1}]"
|
idx = siblings.index(node)
|
||||||
|
# Element may not be found in the siblings if it has gone away
|
||||||
|
idx.nil? ? '[ERROR]' : "[#{idx + 1}]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
result.push selector
|
result.push selector
|
||||||
|
|
|
@ -39,10 +39,29 @@ Capybara::SpecHelper.spec '#has_css?' do
|
||||||
expect(@session).to have_css('h2', id: /2ON/i)
|
expect(@session).to have_css('h2', id: /2ON/i)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should respect scopes' do
|
context 'when scoped' do
|
||||||
@session.within "//p[@id='first']" do
|
it 'should look in the scope' do
|
||||||
expect(@session).to have_css('a#foo')
|
@session.within "//p[@id='first']" do
|
||||||
expect(@session).not_to have_css('a#red')
|
expect(@session).to have_css('a#foo')
|
||||||
|
expect(@session).not_to have_css('a#red')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to generate an error message if the scope is a sibling', :focus_ do
|
||||||
|
el = @session.find(:css, '#first')
|
||||||
|
@session.within el.sibling(:css, '#second') do
|
||||||
|
expect {
|
||||||
|
expect(@session).to have_css('a#not_on_page')
|
||||||
|
}.to raise_error /there were no matches/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to generate an error message if the scope is a sibling from XPath', :focus_ do
|
||||||
|
el = @session.find(:css, '#first').find(:xpath, './following-sibling::*[1]') do
|
||||||
|
expect {
|
||||||
|
expect(el).to have_css('a#not_on_page')
|
||||||
|
}.to raise_error /there were no matches/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue