Select a value from a select element using selenium in Python

Question:

this is my first time using selenium, and I have trouble.

I am trying to access this website, open the ISD dropdown, and select the option "Wayne RESA (82)," which is the value 119.

I have this code

isd = Select(WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.ID,"isds")))) 
isd.select_by_value("119")

But it is not working, and I also tried to click the dropdown menu first using the next code.

isd = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.ID,"isds")))   
accion = ActionChains(browser) 
accion.move_to_element(isd).click().perform()   
elect_isd = Select(isd) select_isd.select_by_value('119')

The previous code opens the dropdown menu, but again nothing more happens.

Any help is well received. Thanks.

Asked By: Victor

||

Answers:

That website does not have the elements you think it has:

enter image description here

Notice how the entry for Alpena-Motnmorency-Alcona ESD (04) is not even in a .

Answered By: Shaheed Haque

You can try this:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()

driver.get("https://www.mischooldata.org/student-attendance")

isd = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,"isds")))
driver.find_element(by=By.XPATH, value='//*[@id="reports-container"]/div/div[1]/div[4]/div[1]/span/div/button').click()
driver.find_element(by=By.XPATH, value='//*[@id="reports-container"]/div/div[1]/div[4]/div[1]/span/div/ul/li[57]/a/label').click()
time.sleep(5)

Hope, it’ll be useful 🙂

Answered By: Ajeet Verma
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.