From 1f510475763ace9f0e947ea4fdffcb2895411cdb Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 14 Sep 2018 10:27:02 -0700 Subject: [PATCH] :element selector should ignore XML namespaces --- lib/capybara/selector.rb | 2 +- lib/capybara/spec/views/with_html5_svg.erb | 20 ++++++++++++++++++++ spec/shared_selenium_session.rb | 21 ++++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/capybara/spec/views/with_html5_svg.erb diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index 9ca4dfe3..fc09cd16 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -468,7 +468,7 @@ end Capybara.add_selector(:element) do xpath do |locator, **| - locator ? XPath.descendant(locator.to_sym) : XPath.descendant + xp = XPath.descendant.where(locator ? XPath.local_name == locator.to_s : nil) end expression_filter(:attributes, matcher: /.+/) do |xpath, name, val| diff --git a/lib/capybara/spec/views/with_html5_svg.erb b/lib/capybara/spec/views/with_html5_svg.erb new file mode 100644 index 00000000..e931f861 --- /dev/null +++ b/lib/capybara/spec/views/with_html5_svg.erb @@ -0,0 +1,20 @@ + + + + Namespace + + +
+ + + + + + + + + +
+ + diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index 83dbdbd2..6da59ad3 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -202,7 +202,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode| expect(element.path).to eq('/HTML/BODY/DIV[2]/A[1]') end - it 'handles namespaces' do + it 'handles namespaces in xhtml' do pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session) session.visit '/with_namespace' rect = session.find(:css, 'div svg rect:first-of-type') @@ -210,6 +210,14 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode| expect(session.find(:xpath, rect.path)).to eq rect end + it 'handles default namespaces in html5' do + pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session) + session.visit '/with_html5_svg' + rect = session.find(:css, 'div svg rect:first-of-type') + expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]") + expect(session.find(:xpath, rect.path)).to eq rect + end + it 'handles case sensitive element names' do pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session) session.visit '/with_namespace' @@ -412,6 +420,17 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode| end end end + + describe ":element selector" do + it "can find html5 svg elements" do + session.visit('with_html5_svg') + expect(session).to have_selector(:element, :svg) + expect(session).to have_selector(:element, :rect, visible: true) + expect(session).to have_selector(:element, :rect, visible: :hidden) + expect(session).to have_selector(:element, :circle) + expect(session).to have_selector(:element, :linearGradient, visible: false) + end + end end def headless_or_remote?