POM in Selenium C#

Page Object Model (POM) is best known for modeling the UI objects of page within test codes was discussed a lot more detail as article as well as in video in our blog as shown below

In this article we will discuss how to work with Page Object Model in Selenium with C# also we will discuss about some of the minor changes in Selenium with C# and Java

Minor Changes in Selenium C#

POM of Java works even without specifying the @FindBy attribute, since by default Java POM picks the WebElements by their ID or Name specified as the name of the property in POM class In C# POM the option is not available and it throws NOSUCHELEMENTEXCEPTION
POM in Java first identifies the element with ID and if it fails, then it try to identify the control using its Name C# it identifies element only with ID but not with Name


Here is the complete video of the above discussion

Here is the snippet of code from the above video


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!!!

Karthik KK


  1. Drew Resner says:

    I attempted to follow your teaching in video 8 POM. I’m getting an error when I write the FindsBy attribute on the How key word – the error is “LaunchQuest.FindsByAttribute does not contain a definition for How”

    This is the code.
    using OpenQA.Selenium;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using OpenQA.Selenium.Support.PageObjects;

    namespace LaunchQuest
    class PersonPageObjects
    [FindsBy(How = How.Id,using=”a.mainNav-person”)]
    public IWebElement ClickPerson { get; set; }

  2. swathi says:

    Hi Karthik,

    I am new to selenium your videos are very helpful, Can you please explain about implicit and explicit waits and when they can be used safely?


  3. Sachin Patil says:

    Hi Karthik,
    These all videos are of great use to people who want to learn Selenium.
    Thanks for these videos. Can you also suggest some dummy sites, where we can practice selenium with some more web elements available.

    • Karthik kk says:

      There is one right here executeautomation.com/demosite/Login.html, not sure if the controls are enough for your practice !!!

  4. Yaswanth says:

    How to handle explicit wait in POM (If we use Page factory). In the Expected conditions class there is no method for webelement. All methods support (By by). So if we take webelement then how to handle this.

  5. Jigna says:

    Hi Karthik,

    I am trying to implement POM in my Selenium c# Nunit framework. Just wanted to ask if it is a good idea to save the ‘Using’ values in an excel sheet and read it from there?
    @FindBy(How=How.id, Using=”abc”);
    Instead of the above statement, can we store the”abc” in an excel sheet and populate it from there? is it a good practice?

    • Karthik kk says:

      HI Jigna,

      Its not a good practice to bring property name from excel sheet, but the best way is to keep them in Java file, since anyways any change has to be modified either in excel or java file, so its better keep them in java file.

      Karthik KK

      • Jigna says:

        I dint quite understand this. did you mean c# files or java doc commented file. My environment is selenium in C#

        • Karthik kk says:

          Oops, since you have mentioned @FindBy(How=How.id, Using=”abc”); I thought you are looking for solution in Java, since in C# there is no @FindBy its only [FindsBy(How = How.Id, Using='abc')]

          Once again, maintaining the identification property in C# file is best practice and recommended.

          Karthik KK

  6. Ravi says:

    Hi Karthik,

    i have created POM code and initialized using Pagefactory class. while executing code i’m getting an exception
    An exception of type ‘System.ArgumentException’ occurred in WebDriver.Support.dll but was not handled in user code

    Additional information: Type of member ‘SelectElement’ is not IWebElement or IList

    public POMTest()
    PageFactory.InitElements(PropertiesCollection.driver, this);

    [FindsBy(How=How.XPath, Using = “//*[text()=’REGISTER’]”)]
    public IWebElement RegisterLink { get; set; }

    [FindsBy(How = How.Name, Using = “firstName”)]
    public IWebElement FirstName { get; set; }

    [FindsBy(How = How.Name, Using = “country”)]
    public SelectElement Country { get; set; }

  7. Babban says:

    With page factore:
    [FindsBy(How = How.Name, Using = “firstName”)]
    public IWebElement FirstName { get; set; }

    How to use explicit wait:
    ?? = expects ‘By’ but we are defining it as ‘IWebelement’

  8. Satyajit Kulkarni says:

    Hi Karthik,
    How to handle explicit wait in POM (If we use Page factory). In the Expected conditions class there is no method for webelement. All methods support (By by). So if we take webelement then how to handle this.
    I am not able to find any solution for that.
    Still i tried below below two lines of code in the method but i am not able to run testcases.
    Here is code which i tried,
    public static void waitUntillElementIsVisible(this IWebElement element)
    driver = ((IWrapsDriver)element).WrappedDriver;
    //code 1
    1. new WebDriverWait(driver, TimeSpan.FromSeconds(new Constant().normalwait)).Until((driver) => element.Displayed);
    //code 2
    2. new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(((By)element)));


  9. Praveen Paluri says:

    Hey karthik ,

    i am looking to log the selenium testcases in C#. Can you please suggest the best way to do so?


Leave a Reply

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