I'm trying to use Page Objects pattern in my UI testing. Many examples suppose to save By (Locator) in class fields. Other recommends to save WebElement (or SelenideElement, if you're using Selenide). Though, both are great for hardcoded locators, I don't see how to use this for locators where the path contains variables.
For example, how to save in class field this locator?
public SelenideElement getTotal(String type) {
return $(By.xpath("//h4[contains(text(), '"+ type +"')]");
}