.parent(cssSelector) return empty when using within shadow DOM
See original GitHub issueWhat is your Scenario?
I’m trying to filter the parents of a node with tag div by using .parent('div')
What is the Current behavior?
No elements has been returned
What is the Expected behavior?
Some elements must be returned like the way it behaves when using with light DOM
What is your public website URL? (or attach your complete example)
https://jsfiddle.net/fc067gv1/7/
What is your TestCafe test code?
index.js
const { Selector } = require("testcafe");
fixture`Shadow DOM Example`.page`https://jsfiddle.net/fc067gv1/7/`;
test.timeouts({ pageLoadTimeout: 30000, pageRequestTimeout: 30000 })(
"Filter parent with css selector when using shadow DOM",
async (t) => {
const outputIframe = Selector("iframe").withAttribute("name", "result");
const host = Selector(() => document.querySelector("#host"));
const shadow = host.shadowRoot();
const type = shadow.find("span").withText("Salary");
const container = type.parent("div");
await t
.wait(5000)
.switchToIframe(outputIframe)
.expect(type.exists)
.ok()
.expect(container.exists)
.ok(); // This will fail
}
);
test("Filter parent with css select when using light DOM", async (t) => {
const outputIframe = Selector("iframe").withAttribute("name", "result");
const host = Selector(() => document.querySelector("#host2"));
const type = host.find("span").withText("Salary");
const container = type.parent("div");
await t
.wait(5000)
.switchToIframe(outputIframe)
.expect(type.exists)
.ok()
.expect(container.exists)
.ok();
});
Your complete configuration file
No response
Your complete test report
No response
Screenshots
No response
Steps to Reproduce
- Run the test code
TestCafe version
1.17.0
Node.js version
v16.13.0
Command-line arguments
testcafe chrome index.js
Browser name(s) and version(s)
Chrome 95.0.4638.69
Platform(s) and version(s)
macOS 11.6
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How to handle elements inside Shadow DOM from Selenium
This returns empty list while there are 3 new downloads. As I found out, only parent elements of #shadow-root (open) tag can be...
Read more >5. Working with the Shadow DOM - Modern JavaScript [Book]
The shadow DOM is essentially a way to define a new DOM tree whose root container, or host, is visible in the document,...
Read more >Everything you need to know about Shadow DOM · GitHub
In a nutshell, Shadow DOM enables local scoping for HTML & CSS. ... ParentNode.append() has no return value, whereas Node. ... shadowRoot returns...
Read more >Style an element's shadow DOM - Polymer Project
Shadow DOM provides a mechanism for encapsulation, meaning that elements inside the shadow DOM don't match selectors outside the shadow DOM.
Read more >Element Selectors | TestCafe Studio
Selectors filter the DOM and return page elements that match user-defined criteria ... Use this element as an entry point to the shadow...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello, Thank you for notifying us about the issue. We reproduced it.
Currently, I can recommend performing the following actions as a workaround: replace this row:
const container = type.parent("div");with the following row:
const container = type.parent(node => node.tagName === 'DIV');We will try to fix the issue as soon as possible. Once we make progress, we will let you know.
We’re closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.