ExecuteAutomation

Page Navigation in Selenium C#

In last post we discussed about Page Object Model in Selenium with C# and we also created a simple page object for the EA Page. In this post we will start working with Page Navigational concept of Page Object Model and try to work with two different pages like Login page and EA page and try to demonstrate the concept. We have already discussed about page navigation concept in Selenium with Java, and in this post we will talk the same concept using Selenium with C#. Here is the complete video of above discussion Here is the complete code from the above video Code for Login and EA Page
class EAPageObject
    {


        public EAPageObject()
        {
            PageFactory.InitElements(PropertiesCollection.driver, this);
        }


        [FindsBy(How = How.Id, Using = "TitleId")]
        public IWebElement ddlTitleID { get; set; }

        [FindsBy(How = How.Name, Using = "Initial")]
        public IWebElement txtInitial { get; set; }


        [FindsBy(How = How.Name, Using = "FirstName")]
        public IWebElement txtFirstName { get; set; }


        [FindsBy(How = How.Name, Using = "MiddleName")]
        public IWebElement txtMiddleName { get; set; }

        [FindsBy(How = How.Name, Using = "Save")]
        public IWebElement btnSave { get; set; }


        public void FillUserForm(string intial, string middleName, string firstName)
        {
            txtInitial.SendKeys(intial);
            txtFirstName.SendKeys(firstName);
            txtMiddleName.SendKeys(middleName);
            btnSave.Click();
        }

}


    //Login Page Object Class
    class LoginPageObject
    {

        public LoginPageObject()
        {
            PageFactory.InitElements(PropertiesCollection.driver, this);
        }


        [FindsBy(How = How.Name, Using = "UserName")]
        public IWebElement txtUserName { get; set; }

        [FindsBy(How = How.Name, Using = "Password")]
        public IWebElement txtPassword { get; set; }

        [FindsBy(How = How.Name, Using = "Login")]
        public IWebElement btnLogin { get; set; }



        public EAPageObject Login(string userName, string password)
        {
            //UserName
            txtUserName.SendKeys(userName);
            //password
            txtPassword.SendKeys(password);
            //Click button
            btnLogin.Submit();

            //Return the page object
            return new EAPageObject();

        }
}

Code for Test Script
            //Login to Application
            LoginPageObject pageLogin = new LoginPageObject();
            EAPageObject pageEA =  pageLogin.Login("execute", "automation");
            //Fill User Details
            pageEA.FillUserForm("KK", "Karthik", "Automation");
Thanks for watching the video and reading the post!! Please leave your comments and let me know if there is anything need to be improved in the post!!! Thanks, Karthik KK