Shadowdom access form selenium javascript/typescript

261 Views Asked by At

I'm trying to get access to some shadow dom elements using selenium in Javascript/Typescript, but can't quite seem to get it to work as expected. I haven't been able to find any javascript specific documentation but have addapted other examples to this:

let shadowHost = await this.driver.findElement(elementLocator("xpath", "//custom-element"));
let testShadow: WebElement = await this.driver.executeScript("return arguments[0].shadowRoot", shadowHost);
debugLog(await testShadow.findElements(By.xpath("//div")))

the testShadow seems to have a findElements function but it gives me a bad locator error:

InvalidArgumentError: invalid argument: invalid locator
         (Session info: chrome=101.0.4951.54)
           at Object.throwDecodedError (/home/bwarner/git/BDD/symbolik-selenium-bdd/node_modules/selenium-webdriver/lib/error.js:522:15)
           at parseHttpResponse (/home/bwarner/git/BDD/symbolik-selenium-bdd/node_modules/selenium-webdriver/lib/http.js:549:13)
           at Executor.execute (/home/bwarner/git/BDD/symbolik-selenium-bdd/node_modules/selenium-webdriver/lib/http.js:475:28)
           at processTicksAndRejections (internal/process/task_queues.js:95:5)
           at async thenableWebDriverProxy.execute (/home/bwarner/git/BDD/symbolik-selenium-bdd/node_modules/selenium-webdriver/lib/webdriver.js:735:17)
           at async ShadowRoot.findElements (/home/bwarner/git/BDD/symbolik-selenium-bdd/node_modules/selenium-webdriver/lib/webdriver.js:2979:20)
           at async World.<anonymous> (/home/bwarner/git/BDD/symbolik-selenium-bdd/features/step_definitions/shadowroot_steps.ts:15:14)

I'm wondering if this is just something that isn't supported at all or if I'm doing something wrong, or if there's another hack that I can do to write some tests.

Logging out testShadow returns:

ShadowRoot {
  driver_: thenableWebDriverProxy {
    session_: Promise { [Session] },
    executor_: Executor { customCommands_: [Map], log_: [Logger], w3c: true },
    fileDetector_: null,
    onQuit_: undefined,
    then: [Function: bound then],
    catch: [Function: bound catch]
  },
  id_: '5bf8d739-abc4-4091-bb72-8bf285dfe363'
}
0

There are 0 best solutions below