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|