Sarmad
Sarmad

Reputation: 323

Selecting options from drop down list in python using Selenium Webdriver

I have tried the SELECT class utility with all it's functions including selectByVisibleText() and others but no success. Following is the div hierarchy of my elements and then is the <select> box which I want to read.

<div class="abc">
  <div class="def">
    <div class="xyz">
       <div></div>
       <select class="qwe" id="asd">
         <option class="zxc" label="test" value="01">01</option>
and options are so on till value 12.

How do I get to select the options using selenium webdriver in python ??

EDIT 1: The code I tried is as follows:

select = Select(browser.find_element_by_id("asd"))
select.select_by_visible_text('04')

And,

 eMonth = browser.find_element_by_id("asd")
 eMonth.send_keys("10")

Upvotes: 1

Views: 1859

Answers (2)

Guy
Guy

Reputation: 50949

You can use Select class with explicit wait

wait = WebDriverWait(driver, 10)
dropDown = wait.until(expected_conditions.visibility_of_element_located((By.ID, 'asd')))
select = Select(dropDown)
select.select_by_value('01')

By the way, selectByVisibleText() is Java syntax.

Upvotes: 1

murali selenium
murali selenium

Reputation: 3927

Mostly select class will work as drop down has select tag. good to have some info like code used and exception faced. i hope you tried with giving wait if fails, sleep.

we can also select drop down values by using sendkeys. below is the command is java

 driver.findElement(By.id("asd")).sendKeys("01");

Thank You, Murali

Upvotes: 1

Related Questions