Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to download a file using Selenium Python

I am trying to download a file using the Selenium library from the source page = "https://ec.europa.eu/info/law/better-regulation/have-your-say/initiatives/12527-Artificial-intelligence-ethical-and-legal-requirements/F2665623_en"
you can see the file at the bottom of website

Following is the code I try to run


from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.options import Options       

driver.get('https://ec.europa.eu/info/law/better-regulation/have-your-say/initiatives/12527-Artificial-intelligence-ethical-and-legal-requirements/F2665640_en')
downloadfile = driver.find_element(By.CLASS_NAME, 'ecl-file__download')
time.sleep(4)
downloadfile.click();

but getting error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ElementClickInterceptedException: Message: element click intercepted: Element <a ecllink="" variant="standalone" class="ecl-file__download ecl-link ecl-link--standalone ecl-link--icon ecl-link--icon-after" href="" download="">...</a> is not clickable at point (237, 571). Other element would receive the click: <p class="wt-paragraph">...</p> (Session info: headless chrome=104.0.5112.101)

>Solution :

Instead of using

downloadfile.click();

You might need to use execute_script function for a, try following

driver.execute_script("arguments[0].click();", download_file)

The following is working code

from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_driver = '\path-to-drive\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.get('https://ec.europa.eu/info/law/better-regulation/have-your-say/initiatives/12527-Artificial-intelligence-ethical-and-legal-requirements/F2665640_en')
download_file = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME, "ecl-file__download")))
driver.execute_script("arguments[0].click();", download_file)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading