Attempting to use shadowRootUnl
Hey, this might be a silly question but I'm trying to use element.shadowRootUnl, which was implemented earlier today, but I'm not entirely sure how to do it. This is what I've attempted so far:
config = {
'showcursor': True,
'forceScopeAccess': True
}
with Camoufox(headless=False, config=config) as browser:
browserContext = browser.new_context()
page = browserContext.new_page()
page.goto('random-web-page')
element = page.locator(".element-class")
shadowRoots = element.shadowRootUnl
But this throws an error because the locator class does not have a shadowRootUnl attribute. How would this be done to get the shadow roots?
Hello,
.shadowRootUnl is meant to be used in page.evaluate:
with Camoufox(headless=False, config={'forceScopeAccess': True}) as browser:
page = browser.new_page()
# Testing site with a closed shadow root
page.goto('https://camoufox.com/tests/shadowdom')
# Pull data (for example, an element's coordinates), or interact with elements in the closed shadow root:
page.evaluate('document.querySelector("#shadow-host").shadowRootUnl.querySelector("input").click()')
Sorry for the lack of documentation, I haven't gotten around to updating it yet for the latest changes made in beta 21.
I'll look into how I can make locator natively search within closed shadow roots.
Hello,
.shadowRootUnlis meant to be used inpage.evaluate:with Camoufox(headless=False, config={'forceScopeAccess': True}) as browser: page = browser.new_page()
# Testing site with a closed shadow root page.goto('https://camoufox.com/tests/shadowdom') # Pull data (for example, an element's coordinates), or interact with elements in the closed shadow root: page.evaluate('document.querySelector("#shadow-host").shadowRootUnl.querySelector("input").click()')Sorry for the lack of documentation, I haven't gotten around to updating it yet for the latest changes made in beta 21.
I'll look into how I can make
locatornatively search within closed shadow roots.
I see, thank you. Would this work for iframes with strict CORS access? It seems that I can get the iframe in a shadowroot but I cannot get the contents within it.
Here is an example how you can implement it for closed shadow roots with CORS: https://github.com/techinz/camoufox-captcha