FindBy annotation used to find a list of WebElements

13,397

Solution 1

As of 2.29.0 of the .NET bindings, this is now no longer true. The FindsBy attribute now will find individual elements or collections of elements. Note that the collection field or property decorated by the FindsBy attribute must be of type IWebElement or IList<IWebElement> in order to be populated by the PageFactory. Any other type will throw an exception.

Solution 2

Try [FindAllBy(How = How.ClassName, Using = "name")] instead.

Share:
13,397

Related videos on Youtube

Bob gilong
Author by

Bob gilong

Updated on September 15, 2022

Comments

  • Bob gilong
    Bob gilong over 1 year

    In java I use code like this to grab a list of WebElements with the same identifier:

    @FindBy(how = How.CLASS_NAME, using = "name")
    private List<WebElement> names;
    

    Now, I'm using c# and I'm trying to do the same thing using:

    [FindsBy(How = How.ClassName, Using = "name")]
    private List<IWebElement> names;
    

    However, this gives the exception:

    System.ArgumentException: Object of type 'Castle.Proxies.IWrapsElementProxy_1' cannot be converted to type 'System.Collections.Generic.List`1[OpenQA.Selenium.IWebElement]'.

    I've tried FindAllBy and FindBys, however those do not seem to be valid. Is there anyway I can do this besides

    names = getDriver().findElements(By.ClassNames("..."))?

  • Bob gilong
    Bob gilong over 11 years
    Does not seem to work, I get the error: Type "FindAllBy" could not be found, I also tried FindBys
  • Joe Coder
    Joe Coder over 11 years
    Which version of WebDriver are you using?
  • ShutterSoul
    ShutterSoul about 10 years
    Use IWebElement element = driver.FindElement(By.XPath(""));