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

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

public void testDropdownall()throws Exception {"");
selenium.windowMaximize();"link=Advanced Search");

//Verifying Element is Present or not here i used xpath to find that

if(selenium.isElementPresent("//select[@name='num']/option[contains(text(),'50 results')]"))

 public void tearDown()throws Exception {

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