WebDriver PageFactory Find Elements List

aeinstein83 picture aeinstein83 · Jan 30, 2015 · Viewed 18.1k times · Source

I have multiple elements on a page and I would like to initialize them using PageFactory.

I have tried using following

@FindBy(xpath = "//*[contains(@class,'x-grid-tree-node-leaf')]")    
    List<WebElement> allElements;

but this returns only one element.

now, if I use the traditional way for finding elements

List<WebElement> allElements = driver.findElements(By.xpath("//*[contains(@class,'x-grid-tree-node-leaf')]"));

this returns 4 elements

any pointers what could be the issue?

Answer

aeinstein83 picture aeinstein83 · Feb 2, 2015
@FindBy(xpath = "//*[contains(@class,'x-grid-tree-node-leaf')]")    
List<WebElement> allElements;

this works. there was bug in my code.