当使用[FindsBy]属性时,在c# /Selenium中将IWebElements作为集合



我试图设置多个iwebelement使用[FindsBy]属性包含在OpenQA.Selenium.Support集合。PageObjects,如下所示。假设我想在实例变量"MyElements"中保存所有"li"元素。

HTML

<ul class="elements">
  <li>e1</li>
  <li>e2</li>
  <li>e3</li>
</ul>
c#

class TopPage {
  [FindsBy(How = How.CssSelector, Using = "ul.elements li")]
  public IWebElement[] MyElements;
}

我怎样才能使它工作?

抱歉,问题解决了:

class TopPage {
    TopPage(IWebDriver driver) {
        PageFactory.InitElements(driver, this);
    }
    [FindsBy(How = How.CssSelector, Using = "ul.elements li")]
    public IList<IWebElement> MyElements;
}

使用IList,而不是Array。谢谢你!

最新更新