Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select from drop-down menu

On website there is a drop-down menu "Best Time to Contact" and I click on it but I can’t choose from the d-d menu. Suggestions?

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


driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")

select = Select(driver.find_element_by_id("RESULT_RadioButton-9").click())
select.select_by_visible_text("Morning").click()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I ran the below code

driver.maximize_window()
wait = WebDriverWait(driver, 30)
select = Select(wait.until(EC.visibility_of_element_located((By.ID, "RESULT_RadioButton-9"))))
select.select_by_visible_text('Evening')

Imports :

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

and it did the trick. This is with explicit waits, which is recommended in Selenium automation.

You should not use .click() here

select = Select(driver.find_element_by_id("RESULT_RadioButton-9").click())

Also, I tested your code without .click(), it works as well.

select = Select(driver.find_element_by_id("RESULT_RadioButton-9"))
select.select_by_visible_text("Morning")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading