question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.parent(cssSelector) return empty when using within shadow DOM

See original GitHub issue

What 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

  1. 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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dositeccommented, Nov 12, 2021

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.

0reactions
github-actions[bot]commented, Nov 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found