mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.04k stars 1.52k forks source link

ElementNotInteractableException when using sendKeys with elements inside a shadow root #1414

Open alvarezguille opened 5 years ago

alvarezguille commented 5 years ago

Initially thought it was the same issue as #1173 but in this case the upload is displayed but in a shadowroot. Reported for Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1503860

System

Testcase

Can be reproduced using https://github.com/Artur-/selenium-firefox-shadowdom

Stacktrace

org.openqa.selenium.ElementNotInteractableException: 
Element <input id="fileInput" type="file"> is not reachable by keyboard
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'WIN-R1JBAO1CNPS', ip: '10.100.24.120', os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\Administrator\AppData\Local\Temp\rust_mozprofile.Xq7p8xxzaXW8, rotatable=false, moz:geckodriverVersion=0.23.0, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, moz:headless=false, platform=ANY, proxy=Proxy(pac: http://127.0.0.1:19876/pac.js), moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=true, browserVersion=63.0, platformVersion=6.1, moz:processID=1916.0, browserName=firefox, javascriptEnabled=true, platformName=windows, setWindowRect=true, moz:webdriverClick=true}]
Session ID: XXXXXXXX-XXXX-XXXX-XXXX-XXXX580b8498
Command duration or timeout: 0 milliseconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
    at com.vaadin.testbench.TestBenchElement.sendKeys(TestBenchElement.java:208)
    at com.vaadin.flow.component.upload.testbench.UploadElement.upload(UploadElement.java:78)
    at com.vaadin.flow.component.upload.testbench.UploadElement.upload(UploadElement.java:47)
    at com.vaadin.flow.component.upload.testbench.test.UploadIT.upload(UploadIT.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
whimboo commented 5 years ago

Note that this has also been filed as https://bugzilla.mozilla.org/show_bug.cgi?id=1503860.

jrobinson01 commented 5 years ago

This is also an issue with type="text" inputs inside a shadowRoot. Should that be filed as a separate issue? I'm getting Element <input id="username" type="text"> is not reachable by keyboard when trying to fill that input with text via sendKeys.

whimboo commented 5 years ago

Shadow DOM is not supported yet. Please give it a read on issue #1428.

jrobinson01 commented 5 years ago

@whimboo Yeah, that's understandable. I had also found the same thing recently... that geckodriver cannot serialize an element's shadowRoot property due to the cyclic references. What I'm also finding though, is that geckodriver CAN serialize and access elements within a shadowRoot. Other actions, like getting their text content, properties, and attributes all work as expected. Here are some selenium logs using webdriverio:

getting an attribute of an input element inside shadow DOM:

[GET] http://127.0.0.1:4444/wd/hub/session/36b990f1-62c0-8749-a65b-8370c7ffd965/element/46f04823-1a89-884a-a983-90831f28e9b6/attribute/placeholder
RESULT "foo"

attempting to set a value for the same input:

[POST] http://127.0.0.1:4444/wd/hub/session/36b990f1-62c0-8749-a65b-8370c7ffd965/element/46f04823-1a89-884a-a983-90831f28e9b6/clear
COMMAND elementSendKeys("46f04823-1a89-884a-a983-90831f28e9b6", "testing")
[POST] http://127.0.0.1:4444/wd/hub/session/36b990f1-62c0-8749-a65b-8370c7ffd965/element/46f04823-1a89-884a-a983-90831f28e9b6/value
DATA { text: 'testing' }
webdriver: request failed due to response error: element not interactable
webdriver: Request failed due to Element <input type="text"> is not reachable by keyboard

So the question is, why is a regular type="text" input element that is visible on screen and interactive, being treated as if it were a hidden element?

whimboo commented 5 years ago

Only commands which interact with the element will check the getPointerInteractablePaintTree(). Most likely in such a case this list doesn't contain the element, which will then cause the failure.

jrobinson01 commented 5 years ago

Is there any initiative to fix/change that?

jrobinson01 commented 5 years ago

https://bugzilla.mozilla.org/show_bug.cgi?id=1445227

fj11 commented 2 years ago

Any update on this issue ?