I'd highly recommend you stop using private fields to access elements on the page. All these eventually end up doing is creating busy work as you attempt to map out all the fields on the page and you end up referencing them a single time anyway. On the same note, you should ideally not use XPath or CSS to locate elements on the page, unless they are a last resort. Stick to using the Playwright Locators, such as getByRole, getByText, getByPlaceholder, etc, as in theory they should make your tests more robust.
That all being said, if you do want to keep mapping out the elements individually, you could do this...
private final Locator logInButton = page.getByRole(BUTTON, new Page.GetByRoleOptions().setExact(true).setName("Log In"));
Then when you want to use this button...
public void clickLoginButton() {
logInButton.click();
}
And if you really wanted to make me cry, you could still use your XPath and do something like this...
private final String logInButton = "//button/div[contains(.,\"Log In\")]";
public void clickLoginButton() {
page.locator("xpath=" + logInButton).click();
}