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.