3

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?

Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
Ryo
  • 2,003
  • 4
  • 27
  • 42

1 Answers1

5

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!

Brian
  • 5,069
  • 7
  • 37
  • 47
Ryo
  • 2,003
  • 4
  • 27
  • 42
  • Accept the answer to your own question, and next time let us know *how* it doesn't work, thank you! – Arran Apr 12 '13 at 08:53
  • I know, but they say "You can accept your own answer in 1 day", I'll do that later. – Ryo Apr 12 '13 at 17:11