[英]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/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae934/details我正在尝试从https://www.virustotal.com/gui/file/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae934/detail获取 Signers、Counter Signers 和 X509 Signers 下的内容
from selenium import webdriver
op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(executable_path="/Desktop/chromedriver", options=op)
details_url = "https://www.virustotal.com/gui/file/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae934/details"
driver.get(details_url)
element = driver.find_element_by_xpath("/html/body/vt-ui-shell")
print(element.text)
The result doesn't include the parts under Signers, Counter Signers and X509 Signers结果不包括签名者、会签者和 X509 签名者下的部分
I also tried to do我也尝试过
driver.find_element_by_xpath("//*[@id="details"]//div/vt-ui-signature-info//vt-ui-expandable/span")
to locate that part, but it ended up giving me找到那个部分,但它最终给了我
NoSuchElementException: Message: no such element: Unable to locate element
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这将打印签名版本信息,同样您必须找到 rool 并调用 shadowroot 并找到其他根的元素
https://bitsofco.de/what-is-the-shadow-dom/ 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 Shadow dom 不是文档的一部分,因此您必须使用 javascript 执行程序来查找其中的元素
The Signers fields eg Microsoft Windows are within nested #shadow-root (open) .签名者字段,例如Microsoft Windows位于嵌套的 #shadow-root (open)中。
To extract the text Microsoft Windows you have to use shadowRoot.querySelector()
and you can use the following Locator Strategy :要提取文本Microsoft Windows您必须使用
shadowRoot.querySelector()
并且可以使用以下定位器策略:
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:控制台 Output:
Microsoft Windows
You can find a couple of relevant discussions in:您可以在以下位置找到一些相关的讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.