ElementClickInterceptedException with EC.element_to_be_click



我试图通过单击下拉菜单中的按钮从CDC网站下载文件(我只是直接访问文件URL,但每次点击下载按钮时,blob URL似乎都会更改在Chrome上检查我的下载历史记录)。单击标题"美国COVID-19疫苗接种数量趋势数据表"可找到此按钮。下面的图表在https://covid.cdc.gov/covid-data-tracker/#vaccination-trends.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
driver_path = "some_path"
vac_trend_url = "https://covid.cdc.gov/covid-data-tracker/#vaccination-trends"
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.get(vac_trend_url)
table_title_xpath = "/html/body/div[7]/div[2]/main/div[2]/div[1]/h4"
table_title = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, table_title_xpath)))
table_title.click()
download_button_xpath = "/html/body/div[7]/div[2]/main/div[2]/div[2]/div[1]/button/.."
download_button = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, download_button_xpath)))
download_button.click()
# ActionChains(driver).move_to_element(WebDriverWait(driver, 5).until(
#    EC.element_to_be_clickable((By.XPATH, download_button_xpath)))).click().perform()

虽然第一次点击会显示下拉菜单中实际的下载按钮,但第二次点击会实际下载文件。

Message: element click intercepted: Element is not clickable at point (1445, 310)

标题解释了我运行上面代码时的错误。当我试图取消ActionChain行注释时,我得到了这里描述的错误,尽管使用了帖子中描述的应该修复该错误的相同方法。按钮似乎没有与其他一些HTML元素重叠,所以我更困惑的问题是什么。有解决办法吗?

编辑:我也尝试了MoveTargetOutOfBoundsException问题与chromedriver版本>74在另一个用户的建议,仍然没有骰子。

这应该只是为您下载文件。通过向元素发送click。

download_button_xpath = "/html/body/div[7]/div[2]/main/div[2]/div[2]/div[1]/button"
download_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, download_button_xpath)))
driver.execute_script("arguments[0].click();", download_button )

相关内容

  • 没有找到相关文章

最新更新