Tuesday 19 June 2012

How to verify value in drop down list.

How to verify value in drop down list.
We somehow manage to find the element on the page but its difficult to fund element with some specific attributes.
Take an example How to find some value is in drop down list or now? 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.ebay.in you will see there is drop down along with search text box.
How to veify a specific value "Collectibles" is in drop down list.

Using Xpath:


verifyElementPresent
//select[@id='_sacat']/option[contains(text(),'Collectibles')]



verifyTrue(selenium.isElementPresent("//select[@id='_sacat']/option[contains(text(),'Collectibles')]"));


Using CSS:


verifyElementPresent
css=select#_sacat>option:contains("Fun")



verifyTrue(selenium.isElementPresent("css=select#_sacat>option:contains(\"Fun\")"));


verifyElementPresent
css=select>option:contains("Fun")




How to select the value in drop down using regular expression. 

There are situation when we need to select the drop down value with some partial text .
With the help of regular expression we can select the drop down value 


select
_sacat
label=regexp:Fun*


selenium.select("_sacat", "label=regexp:Fun*");