1

Has anyone figured out how to access an Input file in the shadow DOM using selenium chrome driver?

at a certain point at the angular.js page a button is clicked and in the function triggered by the event creates this elemnt in the shadow DOM
angular.element('<input type="file" accept=".' + h + '"/>');

I am trying to access the input element so I can bypass the file browser dialog. I am using selenium webdriver V3 and chromedriver 2.25 which I understood from the release notes supports accessing the shadow DOM.

I've tried:
driver.FindElements(By.TagName("input"));
or
object title = js.ExecuteScript("return $(':input')");
which both returns the input elemnents not in the Shadow DOM

and
object title = js.ExecuteScript("return $('body/deep/:input')");
throws unrecognized expression: body /deep/ :input

Is there a way to access this element in order to select a file for the input?

  • Try this js.ExecuteScript("return document.querySelector('* /deep/ input[type=file]')"); – Florent B. Nov 24 '16 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.