Using Selenium & Python I need to click on targets.simple.csv download a .csv
file from this page: https://www.opensanctions.org/datasets/default/
Here is the code I have written:
import pandas as pd
import numpy as np
from datetime import date
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
chromedriver_path = r"./driver/chromedriver"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "https://www.opensanctions.org/datasets/default/"
topics_xpath = '/html/body/div[1]/div/div/div[1]/section[2]/table/tbody/tr[6]/td[2]/a/code'
browser.get(url)
browser.maximize_window()
time.sleep(10) #Wait a little for page to load.
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div[2]/div/div/div[2]/div/button[1]"))).click()
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div/div/div[1]/section[2]/table/tbody/tr[6]/td[2]/a/code"))).click()
But I get this error:
ElementClickInterceptedException: element click intercepted: Element is not clickable at point (360, 1282)
(Session info: chrome=114.0.5735.198)
However, the error does not occur if:
- I run the script
- As soon as the page opens, I manually scroll (with the mouse) where the downloadable csv file is.
If I do so, then the code downloads the .csv file.
Is there a way in Python to scroll to the file I want to download without me having to do it manually?