Skip to content

Using Select Boxes with WebDriver

This is a little update to my previous WebDriver post. The code below allows you to set the content of select boxes by accessing the element directly, in this case using XPath to find the element.

#!/usr/bin/env python

from webdriver_firefox.webdriver import FirefoxLauncher
from webdriver_firefox.webdriver import WebDriver

driver = WebDriver()

elements = driver.find_elements_by_xpath(

select_box = elements[0]
options = select_box.find_elements_by_tag_name("option")

for option in options:
    print option.get_text()

# sets the select box to Username