Home > Software engineering >  Unable to click a Download button on a webpage using Selenium
Unable to click a Download button on a webpage using Selenium

Time:12-24

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"}

CodePudding user response:

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)
  • Related