Friday, January 21, 2011

Select,identify selected and print values in dropdown

@Test
public void testDropdownselectvalue()throws Exception {

selenium.open("http://www.google.com");
selenium.windowMaximize();
selenium.click("link=Advanced Search");
selenium.waitForPageToLoad("50000");
// Print all the available options from the results dropdown in the
String[] options = selenium.getSelectOptions("name=num");
// The above command returns a array of strings(options)
    for (int i = 0; i < options.length; i++) {
System.out.println("Option: " + i + " is " + options[i]);
}
//select value from dropdown
    selenium.select("num", "label=30 results");
    //Print the selected value from dropdown
String s=selenium.getSelectedValue("name=num");
System.out.println("selected value is "+s);

}

3 comments:

  1. Hi Sai,

    I have an issue in selecting dropdown. When i select a value in dropdown, it should display a button. But this event is not occuring. I tried using blur, Focus and all... Need a help from you!!

    ReplyDelete