1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Support XPath queries of non-valid XML attribute names

This commit is contained in:
Thomas Walpole 2018-09-20 15:15:32 -07:00
parent 6038c5e84d
commit a42054fafc
4 changed files with 26 additions and 0 deletions

View file

@ -393,6 +393,7 @@ module Capybara
module RackTest; end
module Selenium; end
require 'capybara/xpath_patches'
require 'capybara/helpers'
require 'capybara/session'
require 'capybara/window'

View file

@ -648,3 +648,7 @@ New line after and before textarea tag
<label for="asterisk_input">With Asterisk<abbr title="required">*</abbr></label>
<input id="asterisk_input" type="number"value="2016"/>
</p>
<p>
<input id="special" {custom}="abcdef" value="custom attribute"/>
</p>

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
module Capybara
module XPathPatches
module Renderer
def attribute(current, name)
return super if name =~ /^[a-zA-Z_:][a-zA-Z0-9_:\.\-]*$/
"#{current}/attribute::*[local-name(.) = #{string_literal(name)}]"
end
end
end
end
XPath::Renderer.prepend(Capybara::XPathPatches::Renderer)

View file

@ -445,6 +445,12 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
expect(session).to have_selector(:element, :circle)
expect(session).to have_selector(:element, :linearGradient, visible: :all)
end
it 'can query attributes with strange characters' do
session.visit('/form')
expect(session).to have_selector(:element, "{custom}": true)
expect(session).to have_selector(:element, "{custom}": 'abcdef')
end
end
end