0

I'm trying to download a csv from this website, by using selenium to click on the "download data" button from Python using this code:

driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver')
URL = 'https://www.stats.govt.nz/experimental/covid-19-data-portal'
driver.get(URL)
element = WebDriverWait(driver, 15).until(
    EC.presence_of_element_located((By.ID, "download_data-show"))
    )
# Or this:
# element = WebDriverWait(driver, 15).until(
#     EC.presence_of_element_located((By.XPATH, '//*[@id="download_data-show"]'))
#     )

element.click()

This is the html code I get when I inspect the button:

<button id="download_data-show" class="btn btn-modal action-button shiny-bound-input" type="button"> Download data </button>

When I run the python code, I'm getting a TimeoutException and when I try with an implicit wait of 30 seconds, I get the following error:

NoSuchElementException: no such element: Unable to locate element: {"method":"link text","selector":"Download data"}
  (Session info: chrome=84.0.4147.135)

Any ideas as to why the element can't be found?

Trizzy
  • 45
  • 6

2 Answers2

1

You should download it from this URL (it's the iframe) https://statisticsnz.shinyapps.io/covid_19_dashboard/ I tested it with your code and it finds the selector.

If you want to use the original links regardless, maybe this will help you: Can't select an Iframe in selenium webdriver

IgnacioDLF
  • 40
  • 7
1

The Problem is, that your button is located in an iframe: enter image description here

here is an answer how to get into the iframe: Select iframe using Python + Selenium

shiny
  • 658
  • 5
  • 8