Pages

Search This Blog

Wednesday, October 6, 2010

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:

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

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


Using CSS:

<tr>
 <td>verifyElementPresent</td>
 <td>css=select#_sacat>option:contains("Fun")</td>
 <td></td>
</tr>

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

<tr>
 <td>verifyElementPresent</td>
 <td>css=select>option:contains("Fun")</td>
 <td></td>
</tr>


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

<tr>
 <td>select</td>
 <td>_sacat</td>
 <td>label=regexp:Fun*</td>
</tr>

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