0

I am working with Java Selenium. And I need to put String line computeEngine.getMachineSeries() from properties inside of my xpath. How can I do this?

 @FindBys({@FindBy(xpath = "//md-option//div[@class='md-text ng-binding'][contains(text(), '"+computeEngine.getMachineSeries()+"')]")})
    List<WebElement> seriesOptionNOne;

I cant use this code above, because of this error: "Attribute value must be constant". How can I do this in another way?

Arnis1305
  • 1
  • 1

2 Answers2

-1

You can try the following solution:

String myString = computeEngine.getMachineSeries();
@FindBys({@FindBy(xpath = "//md-option//div[@class='md-text ng-binding'][contains(., '"+ myString +"')]")})
List<WebElement> seriesOptionNOne;
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Not possible: https://stackoverflow.com/a/10636320/1387701

There is no way to dynamically generate a string used in an annotation. The compiler evaluates annotation metadata for RetentionPolicy.RUNTIME annotations at compile time, but GENERIC_GENERATED_NAME isn't known until runtime. And you can't use generated values for annotations that are RetentionPolicy.SOURCE because they are discarded after compile time, so those generated values would never be known.

DMart
  • 2,401
  • 1
  • 14
  • 19