Fish

Wednesday, December 8, 2010

Verify value in drop down list.

How to verify value in drop down list.


Its difficult to find element with some specific attributes.
Take an example How to find some value is in drop down list or not? 
To find element drop down is easy but to find a drop down having some specific value in their list is difficult.


Go to www.google.com  and click Advanced Search, you will see there are some drop down boxes.

How to verify a specific value "50 results" is in drop down list.




Here is the script for finding the value is in drop down or not





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



if the value 50results are in drop down it will display yes or else u will not get any message..



//select[@name='num']/option[contains(text(),'50 results')]





Here name=num is the name of the dropdown u can see it in HTML code...
We used contains (text(),50 results') .....

No comments:

Post a Comment