Home > other >  Click on button in IFrame with Selenium IDE (Accept cookies)
Click on button in IFrame with Selenium IDE (Accept cookies)

Time:01-04

I want to click on a button that is hosted in some kind of iframe with Selenium IDE extension for FireFox. Unfortunately the "switch to frame" command does not work because it does not find any iFrame.

One example of a website which uses such a cookie dialog is https://www.mueller.de. They seem to use some kind of library.

Can anyone point me in the right direction? What is required to accept the cookie dialog programmatically?

CodePudding user response:

driver.get('https://www.mueller.de/')
time.sleep(30)
def expand_shadow_element(element):
    shadowRoot = driver.execute_script('return arguments[0].shadowRoot.children', element)
    return shadowRoot

host=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"div#usercentrics-root")))
shadow_root = expand_shadow_element(host)
inner = shadow_root[0].find_element(By.XPATH, ".//button[@data-testid='uc-accept-all-button']")
inner.click()

Your elements are in a shadow root you need to expand and then click on the button. You could use .shadowroot depending on the version of selenium you have instead of the function.

  •  Tags:  
  • Related