Home > Mobile >  How do I click a button on cookies pop up using Selenium?
How do I click a button on cookies pop up using Selenium?

Time:06-17

Hi I want to click 'Save Services' using Selenium on this website to make the pop up disappear: shadowroot in devtools

To get into the shadowroot, an easy way is the get it's parent item then use JS to get the object.

Within that returned object you can find your button:

edit:: Updated the code from the original answer. This runs for me:


driver = webdriver.Chrome()
driver.implicitly_wait(10)

url = "https://www.hugoboss.com/uk/home"
driver.get(url)
driver.implicitly_wait(10)
shadowRoot = driver.find_element(By.XPATH,"//div[@id='usercentrics-root']").shadow_root
shadowRoot.find_element(By.CSS_SELECTOR, "button[data-testid='uc-save-button']").click()

#########

Update - a demo of the code working: gif

pip list tells me I'm using:

selenium           4.1.3
  • Related