Search code examples
selenium-webdriverwaithtmlelements

How use waits in Html Elements framework


I have tried to use Html Elements framework. Here are one of my blocks:

@Block(@FindBy(id = "test"))
public class FirstBlock extends HtmlElement {

@FindBy(id = "nameS")
private TextInput id;

@FindBy(id = "saveBt")
private Button add;

public void addNewClient(String idText) {
    add.click();
    id.sendKeys(idText);
}

}

I have initialized page factory like:

PageFactory.initElements(new HtmlElementDecorator(driver), this);

Now I want to wait after add.click(); until next element is present. As I found out where is possibility to use AjaxElementLocatorFactory But how can I make this using Html Elements framework?


Solution

  • HtmlElements use AjaxElementLocatorFactory by default, so you don't need any explicit waits in your code. It will try to find your id element until succeed and then executes sendKeys() on it. In case element wait timeout will be reached, it'll throw ElementNotFound exception.