How to select multiple variables from a dropdown menu in Selenium (python)

Viewed 72

I would like to automatically download different datasets from the Climate World Bank (https://climateknowledgeportal.worldbank.org/download-data)

I would like to create a couple of for loops in order to iterate along the countries and along their subregions.

enter image description here

This is an example of a dataset to download.

However, I have two major problems:

  1. I am not able to select the values from the drop-down menu if a change to the timeseries tab
  2. I do not know how to select the values for subnational unit since it exist only after sub-national units is chosen for area type.

This is the code that I have written until now

from multiprocessing import Value
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os 



wd = webdriver.Chrome('C:/Users/alber/OneDrive/Desktop/UniTn/WebD/chromedriver_win32/chromedriver.exe')
url = "https://climateknowledgeportal.worldbank.org/download-data"
wd.get(url)

download_b = wd.find_element(By.ID,'ncfile')
tab = wd.find_element(by = By.XPATH , value = '//*[@id="data-download-form-container"]/div/ul/li[3]/a')
tab.click()

#WebDriverWait(wd, 15).until(EC.presence_of_element_located((By.ID, "variable")))

select = Select(wd.find_element(by = By.ID, value = "variable"))
select.select_by_visible_text("Mean-Temperature")

select = Select(wd.find_element(by = By.ID, value = "aggregation"))
select.select_by_visible_text("Monthly")

select = Select(wd.find_element(by = By.ID, value = "type"))
select.select_by_visible_text("Sub-national units")
select = Select(wd.find_element(by = By.ID, value = "country"))
select.select_by_visible_text("Italy")
select = Select(wd.find_element(by = By.ID, value = "timeperiod"))
select.select_by_visible_text("1901 - 2021")
download_b.click()

Thank you for your help.

0 Answers
Related