Add support for dynamic locators in page objects with @FindBy annotations
See original GitHub issueBackground
Selenide allows to use page objects with annotations like @FindBy
:
@AndroidFindBy(id = "op_add")
@iOSFindBy(id = "op_add")
private SelenideElement plus;
The problem
It doesn’t allow using of dynamic locators (when “op_add” is not a compile-time constant, but needs to be calculated in runtime).
Suggestion
Selenide could allow using dynamic locators by such an API:
@AndroidFindBy(id = "opa_${zopa}")
@iOSFindBy(id = "${zopa}_opa")
private SelenideElement plus(String zopa);
In this case, plus
would me method, not field - which is even better in terms of page object idea.
And Selenide would need to create a “proxy” object implementing this method on-the-fly.
@BorisOsipov @rosolko @yashaka What do you think?
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (13 by maintainers)
Top Results From Across the Web
Replacement of @Findby in pagefactory for dynamic value ...
The @FindBy() annotation is just a shortcut provided to developers by the PageFactory class. Use of the @FindBy() annotation is not mandatory ...
Read more >WebDriver/PageObject/FindBy: how to specify xpath with ...
I used another workaround for this which will allow us to use dynamic xpath even with page factory. Solution: Add the xpath of...
Read more >Page Object Model (POM) With Page Factory | Selenium Tutorial
@FindBy annotation is used in PageFactory to locate and declare the web elements using different locators. Here, we pass the attribute as well ......
Read more >Adding parameterized FindBy annotation to Selenium Page ...
ParameterizedByBuilder class that is used by Selenium to prepare By (locator) object for the annotated field (with the logic of parameterization)
Read more >Page Object Model using Page Factory in Selenium WebDriver
The @FindBy annotation is the essence of the Page Factory approach. It is used to locate web elements using different locators strategies.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
IMHO all this “FindBy” annotation-based syntax is “magical”, and not straightforward. Moreover @FindBy comes from PageFactory of Selenium Webdriver, where PageFactory was deprecated, correct me If I am wrong regarding deprecation…
I prefer more straight forward style of elemet definition, like:
In case of Mobile, on my projects, I have implemented a wrapper over SelelenideElement, that allows the following style:
I find this style more straightforward, obvious and oop-natural. And more powerful. You can then build your PageObjects like you want as normal java objects.
So I would deprecate FindBy at all:)
it seems we can close it because people didn’t like the idea.