0

I have couple of pages that have similar structure, similar elements. But selectors are different from the first tag.

Example:

Selector for the element on one page:

@FindBy(xpath = "//picture-item//div[@class='files']/button")
private WebElement deleteButton;

Selector for the element on another page:

@FindBy(xpath = "//doc-item//div[@class='files']/button")
private WebElement deleteButton;

I want to have an abstract class, which would have all common elements and each page would extend abstract class, but in the beginning of the selector would use its own tag (picture-item or doc-item).

How to do it, because FindBy doesn't support dynamic locators?

Probably, you would recommend to use following locator in abstract class and don't add any tag in the beginning on some page:

@FindBy(xpath = "//div[@class='files']/button")
private WebElement deleteButton;

But it doesn't work in this way. Because web-site is a single page application and all locators are available, when application is loaded. So, if using this locator I would get a lot of deleteButton elements.

  • What is the idea to have an abstract class? Why not just a regular class? – Alexey R. Apr 10 at 20:51
  • Why to use regular? This abstract class would be a template for pages. But template doesn't equal to full page. There is no need to create an object of the template, specific page should follow this template. – Artur Apr 11 at 6:13
0

Use the implementation of @FindBy directly. That might help.

  • 4
    Please edit your answer to explain how using the implementation of @FindBy directly would solve the OP's issues. – Kate Paulk Apr 11 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.