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
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityI 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
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.