FindBy 注解用于查找 WebElements 列表

2024-02-19

在 java 中,我使用这样的代码来获取具有相同标识符的 WebElements 列表:

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

现在,我正在使用 c#,并且尝试使用以下命令执行相同的操作:

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

然而,这给出了例外:

System.ArgumentException:类型的对象 “Castle.Proxies.IWrapsElementProxy_1”无法转换为类型 'System.Collections.Generic.List`1[OpenQA.Selenium.IWebElement]'。

我尝试过 FindAllBy 和 FindBys,但这些似乎无效。除此之外我还能做吗

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


从 .NET 绑定 2.29.0 开始,这是现在不再正确 https://github.com/SeleniumHQ/selenium/blob/master/dotnet/CHANGELOG. The FindsBy属性现在将查找单个元素或元素集合。请注意,集合字段或属性由FindsBy属性必须是类型IWebElement or IList<IWebElement>为了被填充PageFactory。任何其他类型都会引发异常。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

FindBy 注解用于查找 WebElements 列表 的相关文章

随机推荐