0
0
Selenium Javatesting~20 mins

Shadow DOM element access in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shadow DOM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Shadow DOM Access in Selenium
Which of the following statements correctly describes how Selenium accesses elements inside a Shadow DOM?
ASelenium cannot access Shadow DOM elements at all due to browser security restrictions.
BSelenium requires JavaScript execution to pierce Shadow DOM and access its elements because standard locators do not penetrate Shadow roots.
CShadow DOM elements are accessible only if the shadow root is open and Selenium automatically detects this without extra code.
DSelenium can directly locate elements inside Shadow DOM using standard findElement calls without any extra steps.
Attempts:
2 left
💡 Hint
Think about how Shadow DOM encapsulates elements and how Selenium interacts with the page DOM.
📝 Syntax
intermediate
2:00remaining
Correct Java code to access Shadow DOM element
Given a WebElement host representing a shadow host, which Java Selenium code snippet correctly accesses a button inside its Shadow DOM?
Selenium Java
WebElement host = driver.findElement(By.cssSelector("my-shadow-host"));
A
WebElement shadowRoot = (WebElement) ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot", host);
WebElement button = shadowRoot.findElement(By.cssSelector("button"));
BWebElement button = driver.findElement(By.cssSelector("my-shadow-host button"));
C
WebElement shadowRoot = host.getShadowRoot();
WebElement button = shadowRoot.findElement(By.cssSelector("button"));
DWebElement button = host.findElement(By.cssSelector("::shadow button"));
Attempts:
2 left
💡 Hint
Consider how to get the shadow root using JavaScriptExecutor in Selenium.
rendering
advanced
2:00remaining
What happens when Selenium tries to find Shadow DOM element without shadowRoot?
Consider this code snippet: WebElement button = driver.findElement(By.cssSelector("my-shadow-host button")); What will Selenium do when running this code on a page where 'my-shadow-host' is a shadow host with a button inside its Shadow DOM?
ASelenium returns null without throwing an exception.
BSelenium finds the button inside the Shadow DOM and returns the element successfully.
CSelenium throws a StaleElementReferenceException because the shadow host is detached.
DSelenium throws NoSuchElementException because it cannot pierce the Shadow DOM boundary.
Attempts:
2 left
💡 Hint
Think about how Shadow DOM encapsulates elements from normal DOM queries.
selector
advanced
1:30remaining
Choosing the correct CSS selector for Shadow DOM host
Which CSS selector correctly selects the shadow host element named 'custom-widget' in the DOM?
A.custom-widget
B#custom-widget
Ccustom-widget
Dcustom_widget
Attempts:
2 left
💡 Hint
Shadow hosts are custom elements with tag names, not classes or IDs.
accessibility
expert
2:30remaining
Ensuring accessibility for Shadow DOM elements
When building a web component with Shadow DOM, which practice best ensures that screen readers can access and announce the content inside the Shadow DOM?
AUse appropriate ARIA roles and labels inside the Shadow DOM and ensure the shadow root is open.
BUse aria-hidden="true" on the shadow host element to hide it from screen readers.
CAvoid using Shadow DOM if accessibility is needed because screen readers cannot read Shadow DOM content.
DSet role="presentation" on all elements inside Shadow DOM to simplify accessibility.
Attempts:
2 left
💡 Hint
Think about how ARIA roles and open shadow roots affect accessibility.