Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium | shadow root | Element input is not reachable by keyboard

With Selenium 4.1.2 / Java 11 and a page with "shadow root" elements I have a problem to address a specific input text element.

With this code I reach the input element, the curor is blinking but does not write the sendKeys words:

Thread.sleep(2000);
WebElement inputFIELD = (WebElement) ((JavascriptExecutor)driver).executeScript("return document.querySelector('#TextFieldTEXTFIELD').shadowRoot.querySelector('#vaadin-text-field-input-3 > slot:nth-child(2) > input')");
inputFIELD.sendKeys("test");

The exception to this in the terminal is this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <input> is not reachable by keyboard

I have not found a solution to this so far. Any idea?

I find it strange the cursor find its element but does not write.

>Solution :

You can use JavascriptExecutor to set the values as well.

//inputFIELD.sendKeys("test");
((JavascriptExecutor)driver).executeScript("arguments[0].setAttribute('value', 'test')", inputButton);

or using actions chain:

new Actions(driver).moveToElement(inputButton).sendKeys("test").build().perform();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading