如何解决无法使用 Python Selenium 在 shadow-root打开中定位元素
获取 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)
结果不包括 Signers、Counter Signers 和 X509 Signers 下的部分
我也尝试过
driver.find_element_by_xpath("//*[@id="details"]//div/vt-ui-signature-info//vt-ui-expandable/span")
找到那部分,但它最终给了我
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\"]')")
这会打印签名版本信息,同样你必须找到rool并调用shadowroot并找到其他根的元素
https://bitsofco.de/what-is-the-shadow-dom/
Shadow dom 不是文档的一部分,因此您必须使用 javascript 执行程序来查找其中的元素
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。