Search code examples
javaseleniumxpathfindbythucydides

Why WebElement and List<WebElement> are processed not in the similar way via xpath and List is always null?


I'm using Thucydides 0.9.229 with Selenium shipped with it. To obtain some webelements I try to get them via List

@FindAll({@FindBy(xpath = "//div[text()='Расположение']/../../td[2]//input[@type='text']")})
private List<WebElement> placement;

with no result, the placement is returned null, while here

@FindBy(xpath = "//div[text()='Расположение']/../../td[2]//input[@type='text']")})
private WebElement placement;

there placement is not null, but the correct webelement handled well. As far as I understand, the firs example should return the 1-value list anyway, but even more values if there were some additional elements fitting the criteria. So, what is wrong, why I can't get the list of webelements there?


Solution

  • I have the same issue with @FindAll, and it also returns null.

    However, you can use @FindBy for list of elements too. It may be used to mark a field on a Page Object to indicate an element or a list of elements.

    @FindBy(xpath = "//div[text()='Расположение']/../../td[2]//input[@type='text']")})
    private List<WebElement> placement;