python-3.x - 如何使用 python selenium 处理 cookie 弹出窗口?
问题描述
我在处理此网址https://wax.atomichub.io/drops/36636上的此 cookie 弹出窗口时遇到问题。我不知道我应该在 python 中为此编写什么代码,以便单击Accept All按钮并显示实际页面。需要帮忙!
解决方案
接受所有是 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
推荐阅读
- c# - 如何将这两种方法结合起来?
- java - 获取数组中最便宜的项目组合以达到给定值
- css - 从显示中排除元素
- amazon-web-services - Logstash S3 输出插件中的自定义域
- python - 在 Tensorflow 中使用 py_func - ValueError:找不到回调 pyfunc_0
- java - 如何在运行时用不同数量的 editText 对象填充数组列表?
- python - 从列表或元组创建一个新的 numpy 数组
- git - 从主分支中删除许多提交之一,保留其余提交
- javascript - 比较两个数组中的对象javascript任何附加缺失
- azure-devops - 什么是“PipelinesSDK”用户,为什么将它添加到我的所有代码仓库中?