Monu
Monu

Reputation: 17

Unable to select value from drop down with python selenium webdriver even when elements are visible

html code

</p>
<p>
<label>Capacity:</label>
<select name="capacity">
<option value="Small">Small</option>
<option value="Medium">Medium</option> 
<option value="Large">Large</option>
</select>
</p>
<p>

This is what I have tried so far

policy_mgmt =  Select(mydriver.find_element_by_xpath("//select[@name='Capacity']"))
policy_mgmt.select_by_value("Medium")

Does not throw any error but Medium does not get selected

I also tried below code

mydriver.find_element_by_xpath(".//select[@name='capacity']").click()
mydriver.find_element_by_xpath("//select[@name='capacity'] /option[@value='Medium']").click()

This clicks on the drop down and I can see all the options on the webpage, but it does not select "Medium" as I expect.

Any help will be highly appreciated

Upvotes: 0

Views: 169

Answers (2)

Carlo 1585
Carlo 1585

Reputation: 1477

browser.find_element_by_xpath(".//select[@name='capacity']/option[text()='Medium']").click()

Upvotes: 0

Guy
Guy

Reputation: 50809

xpath is case sensitive, it should be capacity with lowercase 'c'

policy_mgmt = Select(mydriver.find_element_by_xpath("//select[@name='capacity']"))

Upvotes: 2

Related Questions