FindBy Annotations Used to Find a List of WebElements

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

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

Now I am using C # and I am trying to do the same using:

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

However, this gives an exception:

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

I tried FindAllBy and FindBys, however they do not seem valid. Anyway, I can do it except

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

+3
source share
2 answers

Starting with 2.29.0 .NET bindings, this is no longer the case . FindsBy will now find individual items or collections of items. Note that the collection field or property decorated with the FindsBy attribute must be of type IWebElement or IList<IWebElement> in order to be filled with PageFactory . Any other type throws an exception.

+11
source

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

+1
source

Source: https://habr.com/ru/post/957339/


All Articles