1

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.

2
  • What is the idea to have an abstract class? Why not just a regular class?
    – Alexey R.
    Commented Apr 10, 2019 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
    Commented Apr 11, 2019 at 6:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.