Selenium Webdriver and PageFactory initialize List elements

selenium-webdriverwebdriver

I have searched the Selenium Webdriver APi docs hosted on google code. Currently using the PageFactory to initlize my Page objects, but having issue initilizing a list of WebElement.

What I need is a way to initialize a list of elements, ideally a list of drop-down select boxes.

I have looked at the API references to @Findsby and @ByChained but still can not figure out the best way to initlize a list of dropdown select boxes. I COULD have a seperate WebElement for each one and grab the ID but I would like to initlize a list of List selects

Currently I use the following:

public class PageObject {

        @FindBy(id="element_id")
        private WebElement element;

        public getElement() {
          return element;
        }
}

Is there some way I can use something similar to the following that I seek:

public class PageObject {   

    @FindBys(className="selectItmes")
    private List<WebElement> selects;

    public List<WebElement> getSelects() {
      return selects;
    }  
}

Or must I use a single Web Element for each element? 🙁

Update

Anyone know how to use the PageFactory and initlize a List elements; using the FindsBy annotation. I can't find any way of doing this yet there are google issues on the selenium google docs site saying this has been fixed in the Java api bindings and in version 2.12 as it was mistaken disabled in 2.11…. I still can't initialize a list. =/

Best Answer

This feature has been recently added in Selenium 2.0. Check this issue. It is fixed now.

From the documents, you could do something like,

@FindAllBy(className="selectItmes") 
List<WebElement> selects;

If you are interested in the code, check this out