How to interact with shadow elements with selenium webdriver?

Need to automate by interacting with shadow dow, how can i get such element so i can click on that ???

We can not automate this type of element directly via driver.findElement, because multiple shadow roots available in the node amplify-authenticator.

So here we can automate with help of CSS selector (XPath not working here)

We can automate via CSS selector with help of javascript executor

Open the console, write the -

document.querySelector(‘amplify-authenticator’) (Here if Shadow root is not open like close then we can automate with help of WebdriverIO)

here cover the all executeScript root via query selector

Then write the code in our class-

JavascriptExecutor jse = (JavascriptExecutor) driver;

WebElement clearData = (WebElement) jse.executeScript(“paste here executeScrpte”);

String js = “argument[0].setAttribute(‘value’, ‘what you want to send’)”;

((JavascriptExecutor)driver).executeScript(js, username);

1 Like