yandex-qatools / htmlelements

Html Elements is a Java framework providing easy-to-use way of interaction with web-page elements in web-page tests.
Other
271 stars 116 forks source link

Internal selectors return items which have been found by the absolute path #130

Closed IZaiarnyi closed 8 years ago

IZaiarnyi commented 8 years ago

htmlelements-java 1.17

Selectors return items which have been found by the absolute path, instead of a relative path from the class

The page contains a lot of same elements that were described in this class

@FindBy(xpath = "//*[@class='row dialog-item']")
public class SceneDescription extends HtmlElement implements Waiter{
    @FindBy(xpath = "//label")
    HtmlElement selectItemRadio;

    @FindBy(xpath = "//h4")
    HtmlElement displayNameTtl;

    public void selectItem(){
        waitFor(selectItemRadio).click();
    }

    public String getDisplayName(){
        return waitFor(displayNameTtl).getText();
    }
}

I include them in page

public class DescriptionPopup extends AbstractBasePage {
    private List<SceneDescription> sceneDescriptions;

    public void printSceneDescription(){
        for(SceneDescription item: sceneDescriptions){
            System.out.println(item.getDisplayName());
    }
}

and initialize them in parent class

public abstract class AbstractBasePage implements Waiter {
    public AbstractBasePage() {
        HtmlElementLoader.populate(this, getDriver());
    }

printSceneDescription() prints the same name(first element's name) 'sceneDescriptions.size()' times, so the count of element is correct but internal elements are initialized by data from the first found element.

*The selectItemRadio is found by absolute path and it isn't situated in our block //[@class='row dialog-item']"**

The part of Html page was attached partOfDom.txt

pazone commented 8 years ago

xpath selector like "//label" (starts with //) searches elements from the root of your HTML. But if you will use .// prefix it will search inside your current context element. All in all it's better to use css selectors.

IZaiarnyi commented 8 years ago

Thanks a lot