Showing posts with label DropDown. Show all posts
Showing posts with label DropDown. Show all posts

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);

}

Verify value in drop down list.

package test;

import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Dropdownall {
public Selenium selenium;
public SeleniumServer seleniumserver;

  @BeforeClass
  public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testDropdownall()throws Exception {
selenium.open("http://www.google.com");
selenium.windowMaximize();
selenium.click("link=Advanced Search");
selenium.waitForPageToLoad("50000");
//Verifying Element is Present or not here i used xpath to find that
if(selenium.isElementPresent("//select[@name='num']/option[contains(text(),'50 results')]"))
{
System.out.println("ys");
}

}
   
 @AfterClass
 public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();
 
 }
 }