Java Selenide: How to use annotation @Setter for adding String to xpath

287 views Asked by At

I need to find an element by xpath, but some part of xpath always changes and I need to add it directly during the test. If I add annotation @Setter to my Selenide element and try to set a new xpath with String, I always receive an error that I can pass only Selenide element. How can I do it?

 String test;
    @Setter
    @FindBy(xpath = "//div[contains(text(),"+test+"]")
    private
    SelenideElement orgCard;

And here I try to pass String to the xpath:

public static void setXpath( String orgName){

     OrganizationsPage.getInstance().setTest("//div[contains(text()," + orgName + "']");

  }  
1

There are 1 answers

0
Dmytro Stekanov On BEST ANSWER

You can write a method and pass a needed argument to it:

public SelenideElement whatever(String orgCard) {
    return $x("//div[contains(text()," + orgCard + "]");
}

But I also suggest to look at some examples, e.g. there https://github.com/selenide-examples/google