Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created April 22, 2024 07:29
Show Gist options
  • Save SarahElson/e396eb1137020f276633766df8a57076 to your computer and use it in GitHub Desktop.
Save SarahElson/e396eb1137020f276633766df8a57076 to your computer and use it in GitHub Desktop.
How to Handle Shadow Root in Selenium Java
public SearchContext expandRootElement(final WebElement element) {
return (SearchContext) ((JavascriptExecutor) getDriver()).executeScript(
"return arguments[0].shadowRoot", element);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment