1

How to send variable with dynamic value at @findby in POM using java like -

//div[@class='item']/div[@class='containerbody'][@columnid=' "+i+" ']/div/div[contains(@class,'swimLaneheader')] where i is the variable

Please provide me some examples that includes @FindBy, with the dynamic declaration and dynamic value sending.

2

This is not possible. Since Java annotations does not allow dynamic parameterization.

For more details check this answer.

0

Not exactly using @FindBy but the same effect could be achieved with something like that:

private static final String ROW_OF_GIVEN_PERSON = "//tr[contains(.,'%s')]";

public String getRowOfThePerson(String personName) {
    return String.format(ROW_OF_GIVEN_PERSON, personName);
}

WebElement element = driver.findElement(By.xpath(locators.getRowOfThePerson(personFullName)));

Where %s in xpath is replaced with personName given in parameter.

  • 1
    The effect is not the same. @FindBy annotation lets you use PageObject pattern powered by Selenium mechanisms which allow you to initialise the page elements using Java reflection. – Alexey R. Mar 7 '18 at 12:24

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.