The html source is below
<select id="ca_vdcs" class="pulldown small" name="vdc" style="display: none;">
<option>-- Select a vDC --</option>
<option>Platform-VDC-org</option>
</select>
I want to select the 'Platform-VDC-org', but the below code is not working.
select = browser.find_element_by_id('ca_vdcs')
select.find_element_by_xpath("//option[@value='Platform-VDC-org']").click()
The 'Select' class in Selenium WebDriver is used for selecting and deselecting option in a dropdown. The objects of Select type can be initialized by passing the dropdown webElement as parameter to its constructor.
New Selenium IDE A dropdown is represented by <select> tag and the options are represented by <option> tag. To select an option with its value we have to use the selectByValue method and pass the value attribute of the option that we want to select as a parameter to that method.
You should try using the Select()
class. It makes dealing with select elements
much easier.
select = Select(browser.find_element_by_id("ca_vdcs"))
select.select_by_visible_text("Platform-VDC-org")
You can see the WebDriver API bindings in Python here:
http://selenium-python.readthedocs.org/en/latest/api.html
The Select()
class is at section 7.12. UI Support
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With