Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name 'PageFactory' does not exist in the current context

I'm creating a test automation framework in c#. At the top of the project I have "using OpenQA.Selenium.Support.PageObjects;", however when I try to reference PageFactory.initElements(driver, PageName) I'm seeing the message "The name 'PageFactory' does not exist in the current context".

I thought the PageFactory class was included as part of the Selenium.Support nu get package. Tutorials online seem to reference the PageFactory in the same way I am with no extra imports, is there anything I'm missing?

NuGet packages:

  • Using Selenium.WebDriver version 3.9.1
  • Using Selenium.Support version 3.9.1
  • Using NUnit 3.9.0
  • Using NUnit3TestAdapter 3.9.0
  • Microsoft.NET.Test.Sdk 15.5.0
  • Code below:

    using NUnit.Framework;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Support.PageObjects;
    using System;
    using System.IO;
    
    namespace Framework.TestCases
    {
        class TestCase
        {
            [Test]
            public void Test()
            {
                String pathToDrivers = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Drivers";
                IWebDriver driver = new ChromeDriver(pathToDrivers);
                String searchTerm = "Search Term";
    
                driver.Url = "https://website.com/";
                driver.Manage().Window.Maximize();
    
                HomePage homePage = new HomePage(driver);
                PageFactory.initElements(driver, homePage);
            }
        }
    }
    
    like image 788
    Brad White Avatar asked Feb 11 '18 17:02

    Brad White


    1 Answers

    If anyone faces the same issue, please install from NuGet package manager the following: DotNetSeleniumExtras.PageObjects.Core (3.12.0)

    like image 89
    Seema Avatar answered Sep 19 '22 21:09

    Seema