How click a div with selenium in python to download a file (error: rootNode.elementsFromPoint is not a function)
How click a div with selenium in python to download a file (error: rootNode.elementsFromPoint is not a function)
我尝试从 https://charts.youtube.com/charts/TopSongs/ 下载 Youtube 周刊图表作为 csv。 (下载按钮在SVG图标的右上角)
我使用了这段代码并尝试了两种方法来点击它,但都给了我这个错误 selenium.common.exceptions.JavascriptException: Message: javascript error: rootNode.elementsFromPoint is not a function (Session info: chrome=91.0.4472.106)"
这是我的代码,我已经确定我找到了带有 download_button.get_attribute("outerHTML")
的正确 HTML 元素
from selenium.webdriver.common.by import By
from selenium import webdriver
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 = webdriver.Chrome()
driver.maximize_window()
driver.get('https://charts.youtube.com/charts/TopSongs/')
time.sleep(4)
#######first attempt######
download_button = driver.find_element_by_xpath("//div[@class='download-container style-scope ytmc-charts']/paper-icon-button")
action = ActionChains(driver)
action.move_to_element(download_button)
action.click()
action.perform()
#######second attempt######
wait = WebDriverWait(driver, 10)
check_box_el = wait.until(ec.visibility_of_element_located((By.XPATH, "//div[@class='download-container style-scope ytmc-charts']/paper-icon-button")))
ActionChains(driver).move_to_element(check_box_el).click().perform()
driver.quit()
有什么想法吗?谢谢:)
看看这是否有效:-
download_elm = driver.find_element_by_xpath(".//*[@id='download-button']")
driver.execute_script("arguments[0].click();", download_elm)
我尝试从 https://charts.youtube.com/charts/TopSongs/ 下载 Youtube 周刊图表作为 csv。 (下载按钮在SVG图标的右上角)
我使用了这段代码并尝试了两种方法来点击它,但都给了我这个错误 selenium.common.exceptions.JavascriptException: Message: javascript error: rootNode.elementsFromPoint is not a function (Session info: chrome=91.0.4472.106)"
这是我的代码,我已经确定我找到了带有 download_button.get_attribute("outerHTML")
from selenium.webdriver.common.by import By
from selenium import webdriver
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 = webdriver.Chrome()
driver.maximize_window()
driver.get('https://charts.youtube.com/charts/TopSongs/')
time.sleep(4)
#######first attempt######
download_button = driver.find_element_by_xpath("//div[@class='download-container style-scope ytmc-charts']/paper-icon-button")
action = ActionChains(driver)
action.move_to_element(download_button)
action.click()
action.perform()
#######second attempt######
wait = WebDriverWait(driver, 10)
check_box_el = wait.until(ec.visibility_of_element_located((By.XPATH, "//div[@class='download-container style-scope ytmc-charts']/paper-icon-button")))
ActionChains(driver).move_to_element(check_box_el).click().perform()
driver.quit()
有什么想法吗?谢谢:)
看看这是否有效:-
download_elm = driver.find_element_by_xpath(".//*[@id='download-button']")
driver.execute_script("arguments[0].click();", download_elm)