From 39a46bbba0e931458db11bc08bb1e3e6a3455c35 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 15 Aug 2018 10:11:32 -0700 Subject: [PATCH] Fix :element selector without element type --- lib/capybara/selector.rb | 2 +- spec/selector_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index 47f0d6eb..c21f15d8 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -460,7 +460,7 @@ end Capybara.add_selector(:element) do xpath do |locator, **| - XPath.descendant((locator || '@').to_sym) + locator ? XPath.descendant(locator.to_sym) : XPath.descendant end expression_filter(:attributes, matcher: /.+/) do |xpath, name, val| diff --git a/spec/selector_spec.rb b/spec/selector_spec.rb index 48373ac3..57564e2d 100644 --- a/spec/selector_spec.rb +++ b/spec/selector_spec.rb @@ -261,6 +261,10 @@ RSpec.describe Capybara do expect { string.all(:element, 'input', type: 'submit', count: 1) }.not_to raise_error end + it 'works without element type' do + expect(string.find(:element, type: 'submit').value).to eq 'click me' + end + it 'includes wildcarded keys in description' do expect { string.find(:element, 'input', not_there: 'bad', count: 1) } .to(raise_error do |e|