Can't Locate Elments Within Shadow-root (open) Using Python Selenium
I'm trying to get the content under Signers, Counter Signers and X509 Signers from https://www.virustotal.com/gui/file/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae
Solution 1:
element=driver.execute_script(
"return document.querySelector('body file-view').shadowRoot.querySelector('vt-ui-file-details').shadowRoot.querySelector('vt-ui-signature-info').shadowRoot.querySelector('vt-ui-expandable').shadowRoot.querySelector('[class=\"details\"]')")
this prints the signature version information , similarly you have to find the rool and call shadowroot and find the element for other roots
https://bitsofco.de/what-is-the-shadow-dom/
Shadow dom is not part of document so you have to use javascript executor to find elements inside it
Solution 2:
The Signers fields e.g. Microsoft Windows are within nested #shadow-root (open).
Solution
To extract the text Microsoft Windows you have to use shadowRoot.querySelector()
and you can use the following Locator Strategy:
Code Block:
driver.get('https://www.virustotal.com/gui/file/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae934/details') print(driver.execute_script("return document.querySelector('file-view').shadowRoot.querySelector('vt-ui-file-details').shadowRoot.querySelector('vt-ui-signature-info').shadowRoot.querySelector('vt-ui-expandable-detail').shadowRoot.querySelector('slot')").text)
Console Output:
Microsoft Windows
References
You can find a couple of relevant discussions in:
- Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome
- Unable to locate the Sign In element within #shadow-root (open) using Selenium and Python
- Unable to locate the Sign In element within #shadow-root (open) using Selenium and Python
- selenium in python : NoSuchElementException: Message: no such element: Unable to locate element
Post a Comment for "Can't Locate Elments Within Shadow-root (open) Using Python Selenium"