6

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()
1
  • Well how does it not work? Why are you not using select.select_by_visible_text or select.select_by_value? Commented Oct 29, 2013 at 9:29

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

2 Comments

Was trying to find that reference in the documentation using the attached link but couldn't find it. Is that still there or am I looking at the wrong place? Thanks!
@EugeneS You're right, the docs have been reordered I guess. It's section 7.12. UI Support now. I'll update the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.