0

I am new to Page factory model - I need number of elements in list, I am trying in the following way:

**[FindsBy(How = How.XPath, Using = "//*[@id='ABC']/div")]
public List<IWebElement> allElements;
Console.Write("Number of Elements: " +allElements.Count);**

When I run my test I am getting:

ERROR system.argumentexception: object of type 'castle.Proxies.IwrapsElementProxy_1' cannot be converted to type 'System.Collections.Generic.List 1 [OpenQA.Selenim.IWebElemen]'

Not sure what is going wrong here. Any input is much appreciated.

Thank you.

1

I am only on my phone right now so can't try out any tests for this, but the problem here looks like the findsby attribute for the page object factory in Selenium is expecting to locate and return only a single instance of IWebElement rather than the collection you are trying to have it locate.

I'm not sure if there is an additional attribute that tells Web Driver that the locator is for an IEnumerable of elements instead, but that's where I'd start looking.

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.