-1

There are more than one span elements on my html and I want to click Apple but there is a problem that this list have same class and no id. How can I get Apple with @FindBy

<span class="ui-cell-data">Apple</span>
<span class="ui-cell-data">Samsung</span>

I tried something like that but it didn't work.

@FindBy(className = "ui-cell-data:Apple")
WebElement customerName;

1 Answers1

1

You're looking for text() using xpath

@FindBy(xpath = "//span[@class='ui-cell-data'][text()='Apple']")
WebElement customerName;

Note: if there is any way you can identify the element by where it is in the dom, it would probably be better to not use the text. However, sometimes text is the most reliable selector if the product wasn't built with automation in mind.

mrfreester
  • 1,981
  • 2
  • 17
  • 36