How to extract info within a #shadow-root (open) using Selenium Python?

Solution 1:

The products within the website https://www.tiendasjumbo.co/buscar?q=mani are located within a #shadow-root (open).

impulse-search


Solution

To extract the product label you have to use shadowRoot.querySelector() and you can use the following Locator Strategy:

  • Code Block:

    driver.get('https://www.tiendasjumbo.co/buscar?q=mani')
    item = driver.execute_script("return document.querySelector('impulse-search').shadowRoot.querySelector('div.group-name-brand h1.impulse-title span.formatted-text')")
    print(item.text)
    
  • Console Output:

    La especial mezcla de nueces, maní, almendras y marañones x 450 g
    

References

You can find a couple of relevant discussions in:

  • Unable to locate the Sign In element within #shadow-root (open) using Selenium and Python
  • How to locate the First name field within shadow-root (open) within the website https://www.virustotal.com using Selenium and Python