Search code examples
javaseleniumpageobjectsselenide

Private static final WebElement in Page Object Model


I wonder if it is good practice to use a private static final for web elements, and then issue a getter for this web element

example LoginPage:

private static final SelenideElement LOGIN_BUTTON = $(By.xpath("XPath"));

And getter for loginButton...

So is this a good practice?


Solution

  • You won't get any advantages, using static for element fields.

    If you look for examples and tutorials, you won't meet such implementations.

    This is POM approach recommend by Selenide:

    https://selenide.gitbooks.io/user-guide/content/en/pageobjects.html


    You might think about making everything static, not only element fields. Someone likes such kind of stateless implementation, but I believe it's used by a few people and not really popular. There is no articles like "Guys, use static POM, it's much better".