Home > Enterprise >  Select from drop-down menu
Select from drop-down menu

Time:11-23

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()

CodePudding user response:

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")

CodePudding user response:

This worked for me

driver.find_element(By.CSS_SELECTOR, "#RESULT_RadioButton-9 > option:nth-child(2)").click()
  • Related