Monday 30 January 2012

Dropdown box in selenium web driver in .net

To set the desired value into Dropdown box, the below piece of would work fine!
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
//add this name space to access WebDriverWait
using OpenQA.Selenium.Support.UI;
namespace AutomationUsingSelenium
{
    class Program
    {
        public static InternetExplorerDriver WebDriver;
        static void Main(string[] args)
        {                     
        var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
        capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
        WebDriver = new InternetExplorerDriver(capabilitiesInternet);
        WebDriver.Navigate().GoToUrl("http://www.x-rates.com/calculator.html");

 //Get the hold of the dropdown box by Name
 IWebElement setValueConvert = WebDriver.FindElement(By.Name("from"));
//Place the drop down into selectElemnet
 SelectElement clickThisitem=new SelectElement(setValueConvert);
 Thread.Sleep(600);
//Select the Item from dropdown by Index
 clickThisitem.SelectByIndex(12);
//Select the Item from dropdown by Text
 clickThisitem.SelectByText("EUR");


                                                                                                         

         }
    }
}
Wesite Under Test:
Thanks,
Md. Jawed

No comments:

Post a Comment