我正在尝试使用 python selenium 登录 dropbox (https://www.dropbox.com/login) 显然需要接受cookie。
我尝试单击 cookie 接受按钮,但
find_element
没有看到它。
我也尝试先切换到 cookie 横幅,但这也不起作用。
cookie 横幅的 xpath:
//*[@id="ccpa_consent_banner"]
cookie按钮的xpath:
//*[@id="accept_all_cookies_button"]
有什么建议吗?
请参阅以下工作代码及其内嵌说明:
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)