C# Corner SignUp Page Automation 🖥️ Using Selenium Web Driver

In this article, we will see how we can automate the C# Corner Signup page using Selenium Web driver. Selenium is one of the automation testing tools used for the automation of a web application, a Windows or desktop application with the help of Winium, a headless browser application, a mobile Android or iOS app, with the help of Appium etc.
It is developed using Java and its libraries can be used with either C#, PHP, Python, Perl, Ruby, or JavaScript etc. It has various Selenium drivers, such as ChromeDriver, InternetExplorerDriver, GeckoDriver, OperaDriver, SafariDriver etc.
Selenium is language-independent, which means Selenium is developed using Java, and it can be used with either - C#, Java, PHP,
and JavaScript etc. Selenium can be executed on various operating systems like Windows, Linux, MacOS, Solaris etc.
As Selenium is language independent, it is also platform independent. That means the framework that is developed using C# or
Java can be executed in different platforms or operating systems like Windows OS, Mac OS, Linux etc.
Selenium is a library or API which consists of Classes, Methods, Interfaces, etc. to be used and integrated with various
programming languages mentioned above. Selenium is written using one of the most famous programming languages, i.e., Java,
and it's cross-platform.
Each browser has its own driver. For executing the test scripts on their browsers, such as, for executing the Selenium scripts on Chrome, we have Chrome drivers; for executing the Selenium scripts on Internet Explorer, we have Internet Explorer drivers; for executing the Selenium scripts on Safari, we have Safari drivers; for executing the Selenium scripts on Opera, we have Opera drivers.
Selenium Program For C# Corner SignUp
In the below code, I am performing the automation of C# Corner Signup page using Selenium Webdriver since Selenium Webdriver is one of the most powerful tools used for the automation of web applications.
  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Net;    
  5. using System.Text;    
  6. using System.Threading;    
  7. using System.Threading.Tasks;    
  8. using MbUnit.Framework;    
  9. using Microsoft.VisualStudio.TestTools.UnitTesting;    
  10. using OpenQA.Selenium;    
  11. using OpenQA.Selenium.Chrome;    
  12. using OpenQA.Selenium.Support.UI;    
  14. namespace PageObjectModel    
  15. {    
  16.     [TestClass] //[TestFixture]    
  17.     public class CsharpCornerSignUp    
  18.     {    
  19.         IWebDriver webDriver;    
  21.         //This Method will execute before executing Test Method, it is similar to constructor.    
  22.         //[SetUp]    
  23.         //public void Initialization()    
  24.         //{    
  25.         //    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;    
  26.         //    ChromeOptions chromeOptions = new ChromeOptions();    
  27.         //    chromeOptions.AddArgument("disable-infobars");    
  28.         //    webDriver = new ChromeDriver(@"D:\chromedriver_win32", chromeOptions);    
  29.         //    webDriver.Navigate().GoToUrl("https://www.c-sharpcorner.com/");    
  30.         //    webDriver.Manage().Window.Maximize();    
  31.         //    WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  32.         //}    
  33.         public CsharpCornerSignUp()    
  34.         {    
  35.             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;    
  36.             ChromeOptions chromeOptions = new ChromeOptions();    
  37.             chromeOptions.AddArgument("disable-infobars");    
  38.             webDriver = new ChromeDriver(@"D:\chromedriver_win32", chromeOptions);    
  39.             webDriver.Navigate().GoToUrl("https://www.c-sharpcorner.com/");    
  40.             webDriver.Manage().Window.Maximize();    
  41.             WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  42.         }    
  44.         [TestMethod] //[Test]    
  45.         public void CsharpSignUp()    
  46.         {    
  48.             IWebElement signUpClick = webDriver.FindElement(By.XPath("//*[@id='ctl00_HeaderHomeNewDesign_Login1_HyperLinkRegister']"));    
  49.             signUpClick.Click();    
  50.             WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(40));    
  52.             IWebElement enterEmail = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxEmail"));    
  53.             enterEmail.SendKeys("khajamoiz0011@outlook.com");    
  54.             WebDriverWait enterMail = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  56.             IWebElement firstName = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxFirstName"));    
  57.             firstName.SendKeys("Khaja");    
  58.             WebDriverWait fName = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  60.             IWebElement lastName = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxLastName"));    
  61.             lastName.SendKeys("Moizuddin");    
  62.             WebDriverWait lName = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  64.             IWebElement enterPassword = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_TextBoxPassword']"));    
  65.             enterPassword.SendKeys("C#Corner12345");    
  66.             WebDriverWait password = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  68.             IWebElement confirmPassword = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxPasswordConfirm"));    
  69.             confirmPassword.SendKeys("C#Corner12345");    
  70.             WebDriverWait confirmPasswordWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  72.             IWebElement dropcountry = webDriver.FindElement(By.Name("ctl00$ContentMain$DropdownListCountry"));    
  73.             dropcountry.Click();    
  74.             SelectElement select = new SelectElement(dropcountry);    
  75.             select.SelectByValue("India");    
  76.             WebDriverWait dropCountryWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  78.             IWebElement enterzip = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxZip"));    
  79.             enterzip.SendKeys("500076");    
  80.             WebDriverWait enterZipWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  82.             IWebElement entercity = webDriver.FindElement(By.XPath("//*[@id='TextBoxCity']"));    
  83.             entercity.SendKeys("Hyderabad");    
  84.             WebDriverWait enterCityWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  86.             IWebElement selectsecurity = webDriver.FindElement(By.Name("ctl00$ContentMain$DropdownListSecurityQuesion"));    
  87.             SelectElement se = new SelectElement(selectsecurity);    
  88.             se.SelectByValue("What is the name of the company of your first job?");    
  89.             WebDriverWait securityWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  91.             IWebElement answer = webDriver.FindElement(By.Id("ctl00_ContentMain_TextBoxAnswer"));    
  92.             answer.SendKeys("XYZ Technologies");    
  93.             WebDriverWait answerWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  95.            IWebElement registerMe= webDriver.FindElement(By.Name("ctl00$ContentMain$ButtonSave"));  
  96.            registerMe.Click();  
  97.            WebDriverWait answerWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  100.             IWebElement clickhome = webDriver.FindElement(By.XPath("//*[@id='ctl00_HeaderNewDesign1_HeaderMenu']/div/div/ul/li[1]/a"));    
  101.             clickhome.Click();    
  102.             WebDriverWait clickHomeWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  104.             IWebElement searchClick = webDriver.FindElement(By.Name("ctl00$HeaderHomeNewDesign$searchImageButton"));    
  105.             searchClick.Click();    
  106.             WebDriverWait searchClickWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  108.             IWebElement peopleClick = webDriver.FindElement(By.Id("tabAuthorSearch"));    
  109.             peopleClick.Click();    
  110.             WebDriverWait TabWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  112.             IWebElement firstNamePeople = webDriver.FindElement(By.Id("TextBoxFirstName"));    
  113.             firstNamePeople.SendKeys("khaja");    
  114.             WebDriverWait firstNameWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  116.             IWebElement clickgo = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_PanelAuthorSearch']/input[3]"));    
  117.             clickgo.Click();    
  118.             WebDriverWait goWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  120.             IWebElement profileClick = webDriver.FindElement(By.XPath("//*[@id='authorSearchResult']/div/div/ul/li[1]/a"));    
  121.             profileClick.Click();    
  122.             WebDriverWait profileWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  124.             IWebElement articlesClick = webDriver.FindElement(By.XPath("//*[@id='divContributes']/ul/li[1]/a"));    
  125.             articlesClick.Click();    
  126.             WebDriverWait articlesWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  128.             IWebElement articleClick = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_contentBoxUL']/li[1]/div[2]/h3/a"));    
  129.             articleClick.Click();    
  130.             WebDriverWait articleWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));    
  132.             webDriver.Quit();    
  133.         }    
  135.         //This method will execute after executing all the methods.    
  136.         //[FixtureTearDown]    
  137.         //public void FinalCode()    
  138.         //{    
  139.         //    webDriver.Quit();    
  140.         //}    
  142.     }    
  143. }    
In the above program, in constructor CsharpCornerSignUp, this is the code.
  1. public CsharpCornerSignUp() {  
  2.     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  
  3.     ChromeOptions chromeOptions = new ChromeOptions();  
  4.     chromeOptions.AddArgument("disable-infobars");  
  5.     webDriver = new ChromeDriver(@ "D:\chromedriver_win32", chromeOptions);  
  6.     webDriver.Navigate().GoToUrl("https://www.c-sharpcorner.com/");  
  7.     webDriver.Manage().Window.Maximize();  
  8.     WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  9. }  
In the above piece of code, I am navigating to C# Corner website in the constructor by using the latest Chrome drivers downloaded from Selenium's official website. In chromeOptions, I am using "disable-infobars" to remove the popup. Once the automation starts, the popup will appear on the C# Corner webpage. If we don't remove the popup, the controls under the popup will not be able to be identified and automated.
Once the driver is navigated to ChromeDriver by navigating to C# Corner website, here I am maximizing the browser and waiting for 10 seconds using the WebDriverWait class provided by Selenium.
The use of WebDriverWait is that if we provide 10 seconds wait time, suppose the control is identified within 4 seconds, it will not wait for another 6 seconds and will proceed to automate the next control in the sequence.
  1. IWebElement signUpClick = webDriver.FindElement(By.XPath("//*[@id='ctl00_HeaderHomeNewDesign_Login1_HyperLinkRegister']"));  
  2. signUpClick.Click();  
  3. WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(40));  
  4. IWebElement enterEmail = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxEmail"));  
  5. enterEmail.SendKeys("khajamoiz0011@outlook.com");  
  6. WebDriverWait enterMail = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  7. IWebElement firstName = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxFirstName"));  
  8. firstName.SendKeys("Khaja");  
  9. WebDriverWait fName = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
In the above piece of code, once the C# Corner webpage is loaded properly, I am clicking the SignupClick by using its control property as an XPath and waiting for some 40 seconds with WebdriverWait class. Once the page is navigated to signup page after waiting the given time, I am entering the Enter Email by using one of its control property, such as "Name" and entering the emailId. Once the emailId is entered correctly, it will wait for 10 seconds and I am performing the automation on firstName control by using its Name property. Once the control is identified, I am entering the given value as "Khaja".
  1. IWebElement lastName = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxLastName"));  
  2. lastName.SendKeys("Moizuddin");  
  3. WebDriverWait lName = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  4. IWebElement enterPassword = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_TextBoxPassword']"));  
  5. enterPassword.SendKeys("C#Corner12345");  
  6. WebDriverWait password = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  7. IWebElement confirmPassword = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxPasswordConfirm"));  
  8. confirmPassword.SendKeys("C#Corner12345");  
  9. WebDriverWait confirmPasswordWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
In the above code, once the FirstName value is entered, I am performing the automation on LastName control by providing the control property as "Name" and entering the data as "Moizuddin" and waiting for another 10 seconds. 
For entering the password control, I am using its control property as XPath and entering the password as "C#Corner12345" and waiting for the time provided.
Similarly, to automate the "Confirm Password" control, I am using Name property and entering the Confirm Password as "C#Corner12345" and waiting for the time as 10 seconds.
  1. IWebElement dropcountry = webDriver.FindElement(By.Name("ctl00$ContentMain$DropdownListCountry"));  
  2. dropcountry.Click();  
  3. SelectElement select = new SelectElement(dropcountry);  
  4. select.SelectByValue("India");  
  5. WebDriverWait dropCountryWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  6. IWebElement enterzip = webDriver.FindElement(By.Name("ctl00$ContentMain$TextBoxZip"));  
  7. enterzip.SendKeys("500076");  
  8. WebDriverWait enterZipWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  9. IWebElement entercity = webDriver.FindElement(By.XPath("//*[@id='TextBoxCity']"));  
  10. entercity.SendKeys("Hyderabad");  
  11. WebDriverWait enterCityWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
For automating the Country Dropdown, I am identifying this control by its Name property and expanding it. Then, I am selecting the given value that is "India" using the SelectByValue method which is provided by SelectElement class.
For entering the Zip Code, I am using the Name property in order to find a control and entering the value into the given ZipCode textbox with the value "500076". The controls wait for 10 seconds provided with the WebDriverWait class.
In order to automate the City control, we have used XPath locator for finding the control on the webpage. Once the control is identified, I am using SendKeys to enter the value to the City textbox with the value as "Hyderabad".
  1. IWebElement selectsecurity = webDriver.FindElement(By.Name("ctl00$ContentMain$DropdownListSecurityQuesion"));  
  2. SelectElement se = new SelectElement(selectsecurity);  
  3. se.SelectByValue("What is the name of the company of your first job?");  
  4. WebDriverWait securityWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  5. IWebElement answer = webDriver.FindElement(By.Id("ctl00_ContentMain_TextBoxAnswer"));  
  6. answer.SendKeys("XYZ Technologies");  
  7. WebDriverWait answerWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  9. IWebElement registerMe= webDriver.FindElement(By.Name("ctl00$ContentMain$ButtonSave"));  
  10. registerMe.Click();  
  11. WebDriverWait answerWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10))  

From the above code, in order to select a security question from the dropdown, I am using the SelectElement class by passing the webEelement object reference and selecting the value as "What is the name of the company of your first job?".

In order to provide the answer for the above security question, I am finding the answer textbox control with its Control Id as "ctl00_ContentMain_TextBoxAnswer". Once the control is identified, I am providing the input value as XYZ Technologies to the answer textbox.
The next control is Captcha which cannot be automated with the help of Selenium. However, it can be automated by using some third-party DLL.
For clicking the Register button, we have a Name property as it's Control's unique property. Once the control is identified, we can click on it by using the Click() method. 
  1. IWebElement clickhome = webDriver.FindElement(By.XPath("//*[@id='ctl00_HeaderNewDesign1_HeaderMenu']/div/div/ul/li[1]/a"));  
  2. clickhome.Click();  
  3. WebDriverWait clickHomeWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  4. IWebElement searchClick = webDriver.FindElement(By.Name("ctl00$HeaderHomeNewDesign$searchImageButton"));  
  5. searchClick.Click();  
  6. WebDriverWait searchClickWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  7. IWebElement peopleClick = webDriver.FindElement(By.Id("tabAuthorSearch"));  
  8. peopleClick.Click();  
  9. WebDriverWait TabWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));   
Once we have registered to the C# Corner website by providing our information, in the above code, I am just navigating to my C# Corner profile by performing the certain operations like below.
In the above code, I am clicking on the Home button by providing the control property as XPath. Once the control is identified, I am clicking on the Home button using the Click() method.
In order to search for a particular Username, I am trying to find the search control with its Name control property. Once the control is identified, I am clicking it using the Click() method.
Here, we have two different tabs like Content and People. I am clicking on People because we can find the User's profile in the People tab.
To click on a People tab, we have a control property as Id="tabAuthorSearch".
Once the control is identified, I am clicking on the People tab.
  1. IWebElement firstNamePeople = webDriver.FindElement(By.Id("TextBoxFirstName"));  
  2. firstNamePeople.SendKeys("khaja");  
  3. WebDriverWait firstNameWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  4. IWebElement clickgo = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_PanelAuthorSearch']/input[3]"));  
  5. clickgo.Click();  
  6. WebDriverWait goWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  7. IWebElement profileClick = webDriver.FindElement(By.XPath("//*[@id='authorSearchResult']/div/div/ul/li[1]/a"));  
  8. profileClick.Click();  
  9. WebDriverWait profileWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
In the above piece of code, for the First Name textbox, I am identifying it using the Id control property that is Id="TextBoxFirstName". Once the control is identified, I am entering my first name as "Khaja".
To perform a click or to search the UserName "Khaja", I am finding a control with its XPath control property and clicking on the control. 
Once we get the list of C# Corner registered users, I am clicking on my profile by identifying a control with XPath Control Property and clicking on it.
  1. IWebElement articlesClick = webDriver.FindElement(By.XPath("//*[@id='divContributes']/ul/li[1]/a"));  
  2. articlesClick.Click();  
  3. WebDriverWait articlesWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  4. IWebElement articleClick = webDriver.FindElement(By.XPath("//*[@id='ctl00_ContentMain_contentBoxUL']/li[1]/div[2]/h3/a"));  
  5. articleClick.Click();  
  6. WebDriverWait articleWait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  7. webDriver.Quit();  
In the above code, once the page is navigated to my profile, I am clicking on the Articles link by identifying a  control with its XPath property. Once the control is identified, I am clicking on the Articles link and waiting for the provided wait time.
When we get the list of articles, I want to click on the first article. In order to click on it, I am identifying it using its XPath Control property. When the control is identified with XPath property, I am clicking on the first article's link.
When all the control operations are done, I want to close the browser. In order to do that, we need to use the webDriver.Quit() method.
  1. //This method will execute after executing all the methods.  
  2. [FixtureTearDown]  
  3. public void FinalCode()  
  4. {  
  5.  webDriver.Quit();  
  6. }  
The above method, that is, FinalCode(), contains a Selenium attribute [FixtureTearDown]. This method will be executed after executing all the test methods and executing a FinalCode method.
If we want to quit or close a browser, we can use this code in FinalCode Method.
  1. //This Method will execute before executing Test Method, it is similar to constructor.  
  2. [SetUp]  
  3. public void Initialization()  
  4. {  
  5.  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  
  6.  ChromeOptions chromeOptions = new ChromeOptions();  
  7.  chromeOptions.AddArgument("disable-infobars");  
  8.  webDriver = new ChromeDriver(@"D:\chromedriver_win32", chromeOptions);  
  9.  webDriver.Navigate().GoToUrl("https://www.c-sharpcorner.com/");  
  10.  webDriver.Manage().Window.Maximize();  
  11.  WebDriverWait waitForControl = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));  
  12. }  
The above method Initialization() has an attribute [SetUp] which is a part of MbUnit.Framework. It works similar to a constructor and is executed before the execution of the test methods. In order to keep the code or the initialization code, we can keep it in SetUp method instead of keeping it in constructor. When we run or execute our Selenium Scripts, the first SetUp method will be executed. All the methods will be executed later after FixtureTearDown is executed.
To execute the Selenium script with MbUnit's Gallio framework, we need to use [TestFixture] attribute instead of [TestClass] which is above the Selenium Class, as well as, above the Selenium's Test Method. We need to use [Test] attribute instead of [TestMethod].

Similar Articles