Frage

I'm trying to set multiple IWebElements to a collection using [FindsBy] attribute included in OpenQA.Selenium.Support.PageObjects, like following. Suppose I want to hold all "li" elements in instance variable "MyElements".

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;

}

how can I make this work?

War es hilfreich?

Lösung

Sorry guys, solved:

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

Use IList, not an Array. Thank you!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top