I'm writing a script to test an input box embedded into multiple nested shadow DOMs with the structure below. Red boxes are the shadow DOMs (I had to cut off the first one out because it won't fit onto the screenshot) and green box is the element I want to interact with (a text box):
I wrote the script below following the nested shadow DOM guidance here thinking that I need to send the type
command to the final shadowRoot variable. When running it, I get a javascript error: By is not defined
error. I'm weak in JS but I'm pretty sure I have the correct selenium syntax so I can't understand why it's failing to locate the shadow DOM tags.
host = driver.find_element(By.TAG_NAME, "macroponent-f51912f4c700201072b211d4d8c26010")
shadowRoot = driver.execute_script(f"return arguments[0].shadowRoot.findElements(By.tagName('sn-polaris-layout'))[0].shadowRoot.findElements(By.tagName,('sn-polaris-header'))[0].shadowRoot.findElements(By.tagName,('sn-search-input-wrapper'))[0].shadowRoot.findElements(By.tagName,('sn-component-workspace-global-search-typeahead'))[0]", host)
shadowRoot.find_element(By.ID, "sncwsgs-typeahead-input").type({ticket})
Is there something I'm missing here? Is execute_script
not supposed to run a selenium command?
source https://stackoverflow.com/questions/75902715/how-to-interact-with-a-websites-nested-shadow-dom-in-python-selenium
Comments
Post a Comment