question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for dynamic locators in page objects with @FindBy annotations

See original GitHub issue

Background

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:closed
  • Created 4 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
yashakacommented, Feb 4, 2020

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:

foo = $("#foo);

In case of Mobile, on my projects, I have implemented a wrapper over SelelenideElement, that allows the following style:

foobar = drd("foo").ios("bar");

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:)

0reactions
asolntsevcommented, Feb 21, 2021

it seems we can close it because people didn’t like the idea.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found