I was using POM for initializing my elements as below.

[FindsBy(How = How.XPath, Using = "//ion-buttons[2]/button")]
    public IWebElement SearchIcon { get; set; }

    [FindsBy(How = How.CssSelector, Using = "input.searchbar-input")]
    public IWebElement SearchTextbox { get; set; }

    [FindsBy(How = How.ClassName, Using = "item-wrapper")]
    public IWebElement fixedcontent { get; set; }

But how to use below line of code on above format:

IList<IWebElement> propertyList1 = Setup.driver.FindElements(By.ClassName("name"));

In C# you use the following:

[FindsBy(How = How.ClassName, Using = "name')]
private IList<IWebElement> propertyList1 { get; set; }

Btw, notice I've declared the locator as "private". As a general rule you don't make locators in a POM "public".

| improve this answer | |
  • +1 but why add { get; set; }? – FDM Jun 20 '17 at 10:04
  • That's C# shorthand for "use the usual accessor methods". There's a good explanation of it here – NotInventedHere Jun 20 '17 at 11:02
  • Why would you write them for a private variable? Is there any added value versus private IWebElement element;? – FDM Jun 20 '17 at 11:09
  • Your locators should only really be accessed by the page object they belong to. So be default you should always mark them as private unless you have a really good reason not to. Using the propertyList1 example above, lets say you want to get one of the properties in the list. In your page object you would declare a public method that accesses that locator list and then used that method in your test code. You would never access propertyList1 directly in your test. So by declaring it as private you ensure that no one can accidentally do that. – NotInventedHere Jun 20 '17 at 11:27
  • 1
    I just realised I misunderstood your question. The solution I gave declares "propertyList1" as a Property were as the example you gave declares "element" as a Field. Other than it being good OOP practice to use encapsulation, I'm not sure there is a huge difference between the two in this case. It's a pretty big topic though. You might want to check out Difference between Property and Field in C# 3.0+ for a more extensive discussion of it. – NotInventedHere Jun 21 '17 at 10:12

I am providing my answer in java:

public List<WebElement> propertyList1;


@FindBy(how = How.CLASSNAME, Using=”name”))
public List<WebElement> propertyList1;

Additional Information: We can use @FindAll with multiple @FindBy annotations to look for elements that match any of the given locators:

    @FindBy(how=How.ID, using=”username”),
private WebElement user_name;

I would also recommend to read for future reference.

| improve this answer | |
  • Thanks, But im up to C# dude – ChathuD Mar 15 '17 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.