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.

[🐛 Bug]: FindElements By TagName doesn't work anymore inside Shadow root element

See original GitHub issue

What happened?

When using version 4.0.0 and up of Selenium, I get this error now when trying to find elements by tag name inside a shadow root element

javascript error: b.getElementsByTagName is not a function
  (Session info: chrome=95.0.4638.69)

This error isn’t there when I use version 3.141.0 and it’s only when the find element is with tag name as far as I checked.

I’m using the x64 version of ChromeDriver 95.0.4638.69 and the application is in C# with .Net5.0

To reproduce, simply try it with Chrome download page.

How can we reproduce the issue?

[HttpGet("TestShadowRoot")]
        public bool TestShadowRoot()
        {
            try
            {
                var driver = new ChromeDriverNoOptions().GenerateDriver(); //Change this to generate the driver
                driver.Navigate().GoToUrl("chrome://downloads");
                var root = driver.FindElement(By.XPath("/*"));
                var shadowRoot = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].querySelector(arguments[1]).shadowRoot", 
                                                                                          root, 
                                                                                          new string[] { "downloads-manager" });
                var elements = shadowRoot.FindElements(By.TagName("cr-button"));
            }
            catch (Exception ex)
            {
                return false;
            }

            return true;
        }

Relevant log output

javascript error: b.getElementsByTagName is not a function
  (Session info: chrome=95.0.4638.69)

Operating System

Windows 10

Selenium version

C# 4.0.0

What are the browser(s) and version(s) where you see this issue?

Chrome 95.0.4638.69

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 95.0.4638.69

Are you using Selenium Grid?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
derRichtercommented, Nov 18, 2021

we can confirm this problem with chromedriver 96, all fine with driver 95.x on newest chrome-browser 96.x https://bugs.chromium.org/p/chromedriver/issues/detail?id=3958 https://bugs.chromium.org/p/chromedriver/issues/detail?id=3948 we use selenium version 3.141.59, hope there is no force to use selenium 4?

my workaround at the moment is to use or downgrade to version 95.0.4638.69. works also fine with chromium/chrome browser 96.x

good on this constellation is that we got no (error-)message like “This version of ChromeDriver only supports Chrome version…” or “Chrome version must be …”

hope the next stable of chromium-browser 97 is also compatible to chromedriver 95 or the other way round

0reactions
github-actions[bot]commented, Jan 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to automate shadow DOM elements using selenium?
This uses simple css selector to identify elements. WebElement findElement(String cssSelector) : use this method if want single element from DOM.
Read more >
Shadow DOM in Selenium - Titus on Testing
I've seen numerous bugs reported for how Chrome v96 has changed the shadow root return values for Selenium. This is a feature, not...
Read more >
How to fix the 'ShadowRoot cannot be cast to org ... - YouTube
openqa.selenium.WebElement' error in selenium?
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 >
Shadow DOM and the proposed webdriver spec
You must call switchToSubTree(element, index) to interact with anything in a shadow DOM, very similar to how you must call switchToFrame(frame) to interact...
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