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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s