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.

Shadow DOM feature of HtmlUnit doesn't appear to work

See original GitHub issue

HtmlUnitDriver version 2.40.0

I see evidence in the code that the shadow DOM feature is supported by HtmlUnit with version set to “chrome”. When I try using this, however, it doesn’t appear to actually work.

package com.nordstrom.automation.selenium.model;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.Test;

public class FooBar {
	
	@Test
	public void foo() {
		MutableCapabilities caps = new MutableCapabilities();
		caps.setCapability("browserName", "htmlunit");
		caps.setCapability("browserVersion", "chrome");
		caps.setCapability("javascriptEnabled", true);
		HtmlUnitDriver driver = new HtmlUnitDriver(caps);
		driver.get("file:/C:/github/Selenium-Foundation/target-s3/test-classes/ExamplePage.html");
		WebElement elem = driver.findElement(By.cssSelector("div#shadow-root-a"));
		Object bar = ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot;", elem);
	}

}

The value of [bar] comes up null

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rbricommented, Oct 12, 2022

Have written some words - more will follow (see my last commit).

I haven’t found any W3C Java interfaces that declare the shadow hierarchy. Do these even exist?

No idea - i expect we can use the same classes as base classes as we have for the real dom.

Maybe you can start with ShadowRoot as subclass of DocumentFragment and DomShadowRoot as subclass of DomDocumentFragment.

0reactions
sbabcoccommented, Oct 20, 2022

@rbri I’ve started a pull request in my fork of the HtmlUnit project: https://github.com/sbabcoc/htmlunit/pull/1

Read more comments on GitHub >

github_iconTop Results From Across the Web

The javascript engine of htmlunit can't load the generated ...
I am trying to get content of script-generated web page but unfortunately HtmlUnit doesn't seem to work properly. I think the problem is...
Read more >
Not rendering shadow dom elements · Issue #430 - GitHub
I am working on a new project using polymer webcomponents. The problem is that html2canvas is not rendering the shadow dom.
Read more >
Test your elements - Polymer Project
This guide shows you the basics of using Polymer CLI to run unit tests, and how to accomplish various tasks and scenarios using...
Read more >
Working with Shadow DOM Elements using Webdriver
When we try to find Shadow DOM elements using selenium locators, it will throw 'NoSuchElementException'. To access these Shadow DOM elements ...
Read more >
Elemental - [GWT] -
Elemental is a new library for fast, lightweight, and “to the metal” web programming in GWT. It's intended for developers who are comfortable...
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