2

I write test automation using Selenium and C#. I use the Page Object Model consistently. And have had a random bug crop up in my code:

Type of member 'IWebDriver' is not IWebElement or IList

  • strange, how often did your tests flake? when i make an error like that will the test fail 0.1% or 20%, can you give an estimate, just for my curiosity? – globalworming Apr 30 at 21:32
  • Based on your answer, surely that fails every time you use one of the properties you typo'd. And the error tells you exactly what the problem is. How is this strange or on and off? – jonrsharpe Apr 30 at 21:44
  • @globalworming - All of the tests that used the affected page object would fail. In my case, it was about 30 tests (out of 668 total tests). So, almost 5% of the total tests. – Brian Apr 30 at 21:57
  • @jonrsharpe - It's odd because, I couldn't find a cause right away. I just happened on the solution for it today. I was also looking for a specific case online where the root cause of the exception was the same as mine. – Brian Apr 30 at 21:58
  • You couldn't find a cause for why a thing you said was an IWebDriver was neither an IWebElement or IList? Isn't this a compile time error that your IDE can tell you? – jonrsharpe Apr 30 at 22:06
3

This is one of my Page Objects. It works perfectly fine.

public class MyHomePage
{
    IWebDriver driver = null;

    [FindsBy(How = How.LinkText, Using = "Home"), CacheLookup]
    public IWebElement lnkHomeTab { get; set; }

    [FindsBy(How = How.TagName, Using = "Title"), CacheLookup]
    public IWebElement pageTitle { get; set; }

    public MyHomePage(IWebDriver driver)
    {
        this.driver = driver;
        PageFactory.InitElements(driver, this);
    }
}

The example below will produce the exception I mentioned in my post above.

public class MyHomePage
{
    IWebDriver driver = null;

    [FindsBy(How = How.LinkText, Using = "Home"), CacheLookup]
    public IWebElement lnkHomeTab { get; set; }

    [FindsBy(How = How.TagName, Using = "Title"), CacheLookup]
    public IWebDriver pageTitle { get; set; }  <-- The issue is in this line.

    public MyHomePage(IWebDriver driver)
    {
        this.driver = driver;
        PageFactory.InitElements(driver, this);
    }
}

The page object I reference here is pretty static; it doesn't really ever change. I have some more dynamic ones that change frequently.

What I had done in all instances was declare an IWebDriver instead of the expected IWebElement. So, if you see that exception, here is your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.