1

I have an xpath where text may have multiple options, about 8-10.

  1. //name[contains(text(),'abc')]"

  2. //name[contains(text(),'xyz')]"

Conventionally I am using xpath like this:

driver.findElement(By.xpath("//text[contains(text(),'"+variable+ "')]")).click();

Is there a way I can achieve this in Page Factory?

In page factory, we have @FindBy annotation, which take inputs like this:

@FindBy(xpath="//div[contains(text(), 'static text')]").

I am just trying to figure out how to make this dynamic.

Please let me know how can I find this using page factory.

Sun Shine
  • 575
  • 2
  • 6
  • 20
  • " have multiple options, about 8-10", did you mean multiple attributes? – Yu Zhang Aug 27 '15 at 19:55
  • possible duplicate of [WebDriver/PageObject/FindBy: how to specify xpath with dynamic value?](http://stackoverflow.com/questions/21263367/webdriver-pageobject-findby-how-to-specify-xpath-with-dynamic-value) – JeffC Aug 27 '15 at 22:08
  • Not multiple attributes, multiple elements with same xpath and just a different text in attribute span. – Sun Shine Aug 28 '15 at 00:39
  • Kind of duplicate to that, but there is no answer on how to use @FindBy annotation. he wrote a method which I also thought and that does not need any private element to be defined. It can be just done in the method itself where we want to perform the action because it is not updating the web elements value. The question is, finding the web element in a method would be initialized by the PageFactory.initElements method? – Sun Shine Aug 28 '15 at 00:45
  • Yep, most definitely a duplicate, especially with respect to the answer about annotations. Annotations are used at compile time, not run time, and thus their values _must_ be constant. – JimEvans Aug 28 '15 at 17:12

0 Answers0