How to select dropdownlist value using webdriver in python

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 "Platform-VDC-org", but the code below does not work.

 select = browser.find_element_by_id('ca_vdcs') select.find_element_by_xpath("//option[@value='Platform-VDC-org']").click() 
+6
source share
1 answer

You should try using the Select() class. This makes it easier to work with select elements .

 select = Select(browser.find_element_by_id("ca_vdcs")) select.select_by_visible_text("Platform-VDC-org") 

Here you can see the WebDriver API bindings in Python:

http://selenium-python.readthedocs.org/en/latest/api.html

The Select() class is in section 7.12. User interface support

+9
source

Source: https://habr.com/ru/post/956909/


All Articles