首页 > 解决方案 > 如何使用 python selenium 处理 cookie 弹出窗口?

问题描述

我在处理此网址https://wax.atomichub.io/drops/36636上的此 cookie 弹出窗口时遇到问题。我不知道我应该在 python 中为此编写什么代码,以便单击Accept All按钮并显示实际页面。需要帮忙!

标签: python-3.xselenium

解决方案


接受所有是 web 元素,你可以使用下面的 xpath 来定位元素,它只是点击一个 web 元素。

您可以尝试以下代码:

options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome("C:\\Users\\ect\\Desktop\\Selenium+Python\\chromedriver.exe", options=options)
wait = WebDriverWait(driver, 30)
driver.get("https://wax.atomichub.io/drops/36636")
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept All']"))).click()
print("Click operation is successful")

进口:

from selenium.webdriver.support.ui import WebDriverWait

推荐阅读