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

Code for Test Script

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

9 comments

  1. swetha says:

    How to handle controls in modal popup, through page object model?
    By following your instructions, when i click on a link which opens up in pop, i get an error “Null refernce exception was handled”

  2. vivek says:

    Hi Karthik,
    Why can we create just one class that has objects and methods for all the pages in the website. Advantages:
    1) We will have less number of .cs files
    2)we would have some less lines of code
    3) As we will have all the page objects in one file, maintenance will be easier.
    Any thoughts?

    • Karthik kk says:

      Hi Vivek,

      What you have said is opposite to what I have demonstrated, but thats not going to help anyways for bigger projects.

      Thanks,

  3. Sergey says:

    Hello Kartik !
    I really liked your lessons. POM – Great. But you nothing tell about hidden elements and hover actions. Could you give me a simple way to use hover actions (hidden elements) in selenium C#, using custom methods and POM. Thanks a lot !

    • Karthik kk says:

      You cannot hover on an hidden element, since it wont get rendered in DOM though, may I know whats your usecase to hover in hidden elements ?

      • Sergey says:

        Here is my code: (I copied from your lesson in Java)
        public void Property()
        {
        IWebElement menu = driver.FindElement(By.Id("Automation Tools"));
        IWebElement selenium = driver.FindElement(By.Id("Selenium"));
        IWebElement seleniumRC = driver.FindElement(By.Id("Selenium RC"));
        hover(driver, menu);
        hoverAndClick(driver, selenium, seleniumRC);
        }
        public static void hover(IWebDriver driver, IWebElement element)
        {
        Actions action = new Actions(driver);
        action.MoveToElement(element).Perform();
        }
        public static void hoverAndClick(IWebDriver driver, IWebElement elementToHover, IWebElement elementToClick)
        {
        Actions action = new Actions(driver);
        action.MoveToElement(elementToHover).Click(elementToClick).Build().Perform();
        }

        As you can see, this code found a Selenium RC element and click on it.
        I would like to know, can I write this code a shortly and simply.

  4. reachit says:

    Hi Karthik,

    I am building selenium framework (C#) for my project, I am in the initial phase. So I am exploring to keep most of the best practices across. While using PageFactory which you have used in the above code FillUserForm function , i have a scenario where if save button does not exist in the page I need to do some operation for ex: click on new button or some thing. With the code btnSave IWebElment object does not exist it will throw exception. How do you want me to handle this type of scenario.

    Please let me know may be am I thinking in wrong way or not, instead of using properties if I use something like By object (public static By saveBtn = By.Id(“save”) so that I can check if Save By objects exists or not before clicking. I am confused whether do I need to use these
    [FindsBy(How = How.Id, Using = “”)] properties or static By Objects in my page class file. Please help me on this.

Leave a Reply

Your email address will not be published. Required fields are marked *