Detect shadow dom elements when calling `path`

This commit is contained in:
Thomas Walpole 2020-10-10 15:10:56 -07:00
parent f43b6499ec
commit 2ec2a2f295
6 changed files with 23 additions and 2 deletions

View File

@ -493,6 +493,9 @@ private
var xpath = '';
var pos, tempitem2;
if (el.getRootNode && el.getRootNode() instanceof ShadowRoot) {
return ": Shadow DOM element - no XPath :"
};
while(el !== xml.documentElement) {
pos = 0;
tempitem2 = el;

View File

@ -271,5 +271,10 @@ $(function() {
});
$('#multiple-file, #hidden_file').change(function(e){
$('body').append($('<p class="file_change">File input changed</p>'));
})
});
var shadow = document.querySelector('#shadow').attachShadow({mode: 'open'});
var span = document.createElement('span');
span.textContent = 'The things we do in the shadows';
shadow.appendChild(span);
});

View File

@ -409,6 +409,17 @@ Capybara::SpecHelper.spec 'node' do
element = @session.find(:link, 'Second Link')
expect(@session.find(:xpath, element.path)).to eq(element)
end
it 'reports when element in shadow dom', requires: [:shadow_dom] do
@session.visit('/with_js')
shadow = @session.find(:css, '#shadow')
element = @session.evaluate_script(<<~JS, shadow)
(function(root){
return root.shadowRoot.querySelector('span');
})(arguments[0])
JS
expect(element.path).to eq ": Shadow DOM element - no XPath :"
end
end
describe '#trigger', requires: %i[js trigger] do

View File

@ -152,6 +152,7 @@
<p>This is an HTML5 draggable element.</p>
</div>
<div id="shadow"></div>
<script type="text/javascript">
// a javascript comment
var aVar = 123;

View File

@ -8,7 +8,7 @@ class TestClass
end
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation shadow_dom
] do |example|
case example.metadata[:full_description]
when /has_css\? should support case insensitive :class and :id options/

View File

@ -27,6 +27,7 @@ skipped_tests = %i[
scroll
spatial
html_validation
shadow_dom
]
Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
case example.metadata[:full_description]