To get the all checkbox which are not checked and click on those checkbox.
Induce WebDriverWait() and visibility_of_all_elements_located() and following XPATH option.Then iterate the elements and click each of them.
#Get all checkbox which are not selected.
allchekbox=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.XPATH,"//input[@name='YearVar' and not(@checked='checked')]")))
for item in allchekbox:
item.click()
In order to select value for dropdown use selenium select class.
Induce WebDriverWait() and visibility_of_element_located() and either of Xpath option.
XPATH 1:
# Select Item from dropdown
element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//select[starts-with(@name,'DataTables_Table_')]")))
select = Select(element)
select.select_by_value("100")
Or
XPATH 2:
element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//label[normalize-space(text())='Show']/select")))
select = Select(element)
select.select_by_value("100")
Here is the complete Code:
from selenium import webdriver
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.webdriver.support.select import Select
import time
driver = webdriver.Chrome()
driver.get("https://dataunodc.un.org/GSH_app")
driver.maximize_window()
#Switch the iframe in order to access the link
WebDriverWait(driver,15).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@src='https://unodc.shinyapps.io/GSH_App/']")))
#Click on National Data link
WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH,'//ul[@class="nav navbar-nav"]//a[text()="National Data"]'))).click()
#Get all checkbox which are not selected.
allchekbox=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.XPATH,"//input[@name='YearVar' and not(@checked='checked')]")))
#iterate and click each checkbox
for item in allchekbox:
item.click()
#To avoid StaleElementReferenceException add time.sleep()
time.sleep(2)
# Select Item from dropdown
element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//select[starts-with(@name,'DataTables_Table_')]")))
select = Select(element)
select.select_by_value("100")