Added id selector

This commit is contained in:
Jonas Nicklas 2010-08-20 14:46:56 +02:00
parent 1ed5d6fa81
commit 4a3cb69734
2 changed files with 8 additions and 0 deletions

View File

@ -80,4 +80,5 @@ Capybara.configure do |config|
end
Capybara.add_selector(:xpath) { |xpath| xpath }
Capybara.add_selector(:id) { |id| XPath.generate { |x| x.descendant(:*)[x.attr(:id) == id] } }
Capybara.add_selector(:css) { |css| XPath::HTML.from_css(css) }

View File

@ -42,6 +42,13 @@ shared_examples_for "find" do
end
end
context "with id selectors" do
it "should find the first element using the given locator" do
@session.find(:id, 'john_monkey').text.should == 'Monkey John'
@session.find(:id, 'red').text.should == 'Redirect'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.find(:xpath, '//h1').text.should == 'This is a test'