dropbox cookies on banner

40 Views Asked by At

I'm trying to login to dropbox using python selenium (https://www.dropbox.com/login) Obviously cookie acceptance is required.

I tried to click on the cookie accept button, but find_element doesn't see it. I also tried to first switch to the cookie banner, but that doesn't work either.

xpath of the cookie banner: //*[@id="ccpa_consent_banner"]

xpath of cookie button: //*[@id="accept_all_cookies_button"]

Any suggestions?

1

There are 1 best solutions below

2
Shawn On

Root cause of the issue: Desired element is located within IFRAME, you need to switch into it before performing click() on Accept all button.

Assuming you are using PYTHON as your binding language, refer the below code.

Solution: Working code with in-line explanation:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.dropbox.com/login")
wait = WebDriverWait(driver,10)

# Below 2 lines will switch driver context into the 2 nested IFRAMES
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@id='consent-iframe']")))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@id='ccpa-iframe']")))

# Below line will click on Accept All button
wait.until(EC.element_to_be_clickable((By.ID, "accept_all_cookies_button"))).click()

# Below line is used to come out of IFRAME
driver.switch_to.default_content()
time.sleep(10)