0

I'm trying to automate downloading of csv files :

Once I open the page, I scroll to where the download button is, and try to find element and click it.

I have tried various ways to find element using selenium but no luck. Below is the code that I have tried.

from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.australianretirementtrust.com.au/investments/performance/accumulation/unit-price-graphs?id=SOL&optionCode=11")
driver.maximize_window()
driver.execute_script("window.scrollTo(0,1650)")
driver.find_element(By.CLASS_NAME,"DownloadButton").click()

Is something blocking the Download button that I'm not seeing?

The error printed in my terminal:

Message: no such element: Unable to locate element: {"method":"css selector","selector":".DownloadButton"}
Stickle
  • 15
  • 6

1 Answers1

1

There is an iframe. The Download button is inside an iframe, you need to switch to iframe first and then click on the download button.

You can use frameId or frame name to switch to the exact frame.

driver.switch_to.frame(2)
theNishant
  • 663
  • 5
  • 15
  • Thank you @theNishant, that worked. If i may ask a follow up here - I tried running the below code the browser seems to close before the download is completed. Is there any way around this, not sure why the browser window closes when there is no '''driver.close()''' code included. – Stickle Dec 23 '22 at 13:29
  • def Art_prices(url): driver = webdriver.Chrome() driver.get(url) driver.maximize_window() driver.execute_script("window.scrollTo(0,1650)") driver.switch_to.frame(2) Button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "DownloadButton"))) Button.click() Art_prices("https://www.australianretirementtrust.com.au/investments/performance/accumulation/unit-price-graphs?id=SOL&optionCode=11") – Stickle Dec 23 '22 at 13:30
  • Hey @Stickle you can try https://stackoverflow.com/a/51949811/7787197 this. – theNishant Dec 24 '22 at 15:57