How to select/get drop down option in Selenium 2
in ruby for constantly using, add follow:
module Selenium
module WebDriver
class Element
def select(value)
self.find_elements(:tag_name => "option").find do |option|
if option.text == value
option.click
return
end
end
end
end
end
and you will be able to select value:
browser.find_element(:xpath, ".//xpath").select("Value")
Try using:
selenium.select("id=items","label=engineering")
or
selenium.select("id=items","index=3")
Take a look at the section about filling in forms using webdriver in the selenium documentation and the javadoc for the Select class.
To select an option based on the label:
Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));
select.deselectAll();
select.selectByVisibleText("Value1");
To get the first selected value:
WebElement option = select.getFirstSelectedOption()
driver.findElement(By.id("id_dropdown_menu")).click();
driver.findElement(By.xpath("xpath_from_seleniumIDE")).click();