2

I'm trying to get the content under Signers, Counter Signers and X509 Signers from https://www.virustotal.com/gui/file/03d1316407796b32c03f17f819cca5bede2b0504ecdb7ba3b845c1ed618ae934/details

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

result

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
Joanna
  • 47
  • 1
  • 6

2 Answers2

2
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

PDHide
  • 18,113
  • 2
  • 31
  • 46
0

The Signers fields e.g. Microsoft Windows are within nested #shadow-root (open).

shadowroot


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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you so much for your help! I tried it and it worked well. However, I kinda need everything in the signature part and I'm still having a hard time. I edited my post, can you please help me? Thanks in advance! – Joanna Dec 26 '20 at 14:53
  • @Joanna Sounds like a completely different issue all together. Can you raise a new question as per your new requirement? Stackoverflow contributors will be happy to help you out. – undetected Selenium Dec 26 '20 at 18:02
  • Done! Thanks. This is my new question post https://stackoverflow.com/questions/65462625/cant-locate-specific-elements-using-python-selenium-and-shadowroot-queryselecto – Joanna Dec 27 '20 at 03:24