用于查找WebElement列表的FindBy批注 [英] FindBy annotation used to find a list of WebElements
问题描述
在Java中,我使用如下代码来获取具有相同标识符的WebElement列表:
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;
现在,我正在使用c#,并且正在尝试使用以下方法做同样的事情:
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;
但是,这给出了例外:
System.ArgumentException:类型的对象 无法将"Castle.Proxies.IWrapsElementProxy_1"转换为类型 'System.Collections.Generic.List`1 [OpenQA.Selenium.IWebElement]'.
System.ArgumentException: Object of type 'Castle.Proxies.IWrapsElementProxy_1' cannot be converted to type 'System.Collections.Generic.List`1[OpenQA.Selenium.IWebElement]'.
我已经尝试过FindAllBy和FindBys,但是这些似乎无效.反正还有什么我可以做的
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("..."))
?
推荐答案
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.
这篇关于用于查找WebElement列表的FindBy批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!