How to handle the popup “Accepting all cookies” when the element is data-testid – Using Selenium in Python

The element Accept All is within #shadow-root (open). Solution To click on Accept All you have to use shadowRoot.querySelector() and you can use the following Locator Strategy: Code Block: driver.get(“https://www.kostal-solar-portal.com/#/”) time.sleep(5) element = driver.execute_script(“””return document.querySelector(‘#usercentrics-root’).shadowRoot.querySelector(“button[data-testid=’uc-accept-all-button’]”)”””) element.click() References You can find a couple of relevant discussions in: Can’t locate elments within shadow-root (open) using Python Selenium … Read more

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

The First name field within the website https://www.virustotal.com/gui/join-us is located deep within multiple #shadow-root (open). Solution To send a character sequence to the First name field you have to use shadowRoot.querySelector() and you can use the following Locator Strategy: Code Block: from selenium import webdriver import time options = webdriver.ChromeOptions() options.add_argument(“start-maximized”) options.add_experimental_option(“excludeSwitches”, [“enable-automation”]) options.add_experimental_option(‘useAutomationExtension’, False) … Read more

How to get past a cookie agreement page using Python and Selenium?

The element Alles akzeptieren is within #shadow-root (open). Solution To click on Alles akzeptieren you have to use shadowRoot.querySelector() and you can use the following Locator Strategy: Code Block: driver.get(“https://www.heise.de/download/”) time.sleep(5) element = driver.execute_script(“””return document.querySelector(‘#usercentrics-root’).shadowRoot.querySelector(‘footer div div div button[data-testid=”uc-accept-all-button”]’)”””) element.click() Browser Snapshot: References You can find a couple of relevant discussions in: Can’t locate elments … Read more

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

The products within the website https://www.tiendasjumbo.co/buscar?q=mani are located within a #shadow-root (open). 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 … Read more