0

i am defining 2 variables in Selenium like this:

@FindBy(xpath = "//span[contains(text(),'€11')]")
    private WebElement singleTicket;

@FindBy(xpath = "//span[contains(text(),'€19')]")
    private WebElement returnTicket;`

i need to pass different values in these variables for different tests e.g. "$12" but i dont want to create more variables in my page object with different prices. what is a good solution for this?

0

1 Answer 1

1

There is no way to pass parameter to @FindBy annotation. But you can write a custom function to get webelement based on specific value and tag too. so you don't need to create separate element everytime. Please have a look on below function.

   public  WebElement getWebElementForSpecificText(String tagName, String text) {
        String formXpath= ".//"+tagName+"[contains(text(),'"+text+"')]";
        return driver.findElement(By.xpath(formXpath));
    }

Yu can call this function as mentioned below:

getWebElementForSpecificText("span", "€11");
getWebElementForSpecificText("span", "€12");
getWebElementForSpecificText("span", "€19");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.