Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:57:13+00:00 2026-05-23T08:57:13+00:00

I am trying to create WebDriver UI tests framework using Page Object pattern, using

  • 0

I am trying to create WebDriver UI tests framework using Page Object pattern, using the following URL as a reference: http://www.peternewhook.com/2010/09/automated-testing-pageobjects-webdriver/

As per example I have created 3 classes (see below). The problem is with the line return PageFactory.InitElements(_driver, page); in the Search method of the SearchPage class.

When I try to build I get the following error:

The type ‘OpenQA.Selenium.ISearchContext’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WebDriver

Fair enough, as I am referencing WebDriver.Common.dll, so I tried removing it and added WebDriver.dll to my References and all of a sudden I get the following when I build:

Cannot implicitly convert type ‘void’ to ‘ConsoleApplication1.ResultsPage’

and it fails on the same line; when I hover over it, it says:

Cannot convert expression type ‘void’ to ‘ConsoleApplication1.ResultsPage’.

I also tried referencing both assemblies and thought I could use different usings but it is a no-go, didn’t work.

Why can’t PageFactory.InitElements be returned when using WebDriver.dll?

Is there a way around it, or can I achieve the same result by changing the architecture slightly?
Your help is much appreciated. Thanks.

using OpenQA.Selenium;

namespace ConsoleApplication1
{
    public class Page
    {
        public IWebDriver _driver;

        public Page(IWebDriver driver)
        {
            this._driver = driver;
        }
    }
}

using OpenQA.Selenium;

namespace ConsoleApplication1
{
    public class ResultsPage : Page
    {
        public ResultsPage(IWebDriver driver)
            : base(driver)
        {
        }

        private IWebElement count;

        public string GetPagesReturned()
        {
            return count.Text;
        }
    }
}

using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;

namespace ConsoleApplication1
{
    public class SearchPage : Page
    {
        public SearchPage(IWebDriver driver) : base(driver)
        {
        }

        private IWebElement q;
        private IWebElement go;

        public ResultsPage Search(string searchStatement)
        {
            q.SendKeys(searchStatement);
            go.Click();
            ResultsPage page = new ResultsPage(_driver);
            return PageFactory.InitElements(_driver, page);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:57:13+00:00Added an answer on May 23, 2026 at 8:57 am

    The problem is that PageFactory.InitElements() returns void. Rather, it modifies the page you’ve passed in. Your code should look something like this:

    public ResultsPage Search(string searchStatement)
    {
        q.SendKeys(searchStatement);
        go.Click();
        ResultsPage page = new ResultsPage(_driver);
        PageFactory.InitElements(_driver, page);
        return page;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a user account in a test. But getting a Object reference
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
Trying to create a list to return some JSON data to a view. Following
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I'm trying create a small http proxy service. This is not working so well.
Trying to create an object in Javascript (for Appcelerator/Titanium). The object is defined like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.