The page object model in Selenium has you create pageobject classes that represent pages. These classes would contain object locators as well as functions that are relevant for that page.
For example:
public class LoginPage(){
@FindBy(id="user")
WebElement username;
@FindBy(id="pass")
WebElement password;
@FindBy(id="submit")
WebElement submitButton;
//various methods like login
}
The problem is when we have dynamic elements appearing on the page. For example, there's a link that will appear dynamically (say a chat link only if certain conditions are met).
What is the best practice for declaring such dynamic elements in the page class?
We cannot use @FindBy
because that will cause class instantiation to fail if that element isn't present in the UI.
When using page object model and you create pageobject classes that represent pages if you expect the element to be loaded through some AJAX which might not be present immediately on the page already as an example the
email
field you can use the WebDriverWait support with a normal locator factory as follows:Code Block: