ShadowRoot issue (driver 96+)

921 views
Skip to first unread message

Dav vid

unread,
Nov 18, 2021, 5:27:07 AM11/18/21
to ChromeDriver Users
Exception:

(java.lang.ClassCastException: class com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to class org.openqa.selenium.WebElement (com.google.common.collect.Maps$TransformedEntriesMap and org.openqa.selenium.WebElement are in unnamed module of loader 'app'))

Code:
    public WebElement getShadowRoot() {
        return (WebElement) driver.executeScript(String.format("return document.querySelector('#%s').shadowRoot", shadowHostId));
    }

Is it a known issue ?

Steven Erat

unread,
Nov 18, 2021, 6:22:56 PM11/18/21
to ChromeDriver Users
This broke us too on the same issue, testing the chrome://downloads content.

Chromedriver 96 lists the following release note:
  1. Resolved issue 3445: Impossible to access elements in iframe inside a shadow root [Pri-3]
No success trying to work with TransformedEntriesMap thus far.

Steven Erat

unread,
Nov 19, 2021, 9:34:46 AM11/19/21
to ChromeDriver Users
Issues logged for this:


It appears the only current resolution is to update to Selenium 4 and then cast the return type to SearchContext instead of WebElement.

While possible to downgrade ChromeDriver to v95 with Selenium 3.14.x, when Chrome 97 is released in 2022 then ChromeDriver 95 will no longer work.  (ChromeDriver version supports equivalent Chrome version + 1)

Steven Erat

unread,
Nov 19, 2021, 2:22:13 PM11/19/21
to ChromeDriver Users
A workaround for Selenium 3.14.x is provided at:
https://github.com/SeleniumHQ/selenium/issues/10050#issuecomment-974335337
Reply all
Reply to author
Forward
0 new messages