sclevine / agouti

A WebDriver client and acceptance testing library for Go
MIT License
821 stars 103 forks source link

Find element based on Javascript selector. #195

Open dglsparsons opened 5 years ago

dglsparsons commented 5 years ago

Hi,

We use shadowDOM fairly extensively in our codebase, and wanted to automate a suite of tests using agouti. However - I'm hitting a major blocker accessing any DOM elements within the shadow root on the page.

It's not part of the webdriver spec, so not that surprising that there's no built in behaviour for this - the common workaround seems to be running custom javascript to explore the DOM / find elements.

E.G

document.querySelector("some-element").shadowRoot.querySelector("target-element")

I've tried doing this through the RunScript API -

Eventually(func() string {
    var result string
    p.RunScript(
        `return document.querySelector("some-element").shadowRoot.querySelector("target-element"),
        nil,
        &result,
    )
    return result
}).Should(Equal("wat"))

However, it seems to return nothing, and i can't find any way of getting an *agouti.Selection out of the javascript return.

Is there any way to achieve this?