Get value from Textbox in .Net(C#)

Supposed that you have html code something as below:
And you have to get the values from input box mention above. The above input box can be textbox, label or anything.
Then in that case you have to use below piece of code to retrieve the value from Text Box:

//Here I will find the input control using Name, but you can try using Id/css.
IWebElement outPutvalue = WebDriver.FindElement(By.Name(“outV”));string currencyValue =outPutvalue.GetAttribute(“value”) ;
Console.WriteLine(“Value from textbox is: “ + currencyValue);

Output:

Value from textbox is:  1234

The Whole Piece of code would look like this:

using OpenQA.Selenium;
using OpenQA.Selenium.IE;
//add this name space to access WebDriverWait
using OpenQA.Selenium.Support.UI;
using System.Threading;
public void MyTestInitialize()
 {
  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”);
  IWebElement outPutvalue = WebDriver.FindElement(By.Name(“outV”));
  string currencyValue =outPutvalue.GetAttribute(“value”) ;
   Console.WriteLine(“Value from textbox is: “ +currencyValue);
}

Thanks,
Md. jawed

3 thoughts on “Get value from Textbox in .Net(C#)

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