SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Enable Click Button and Click Element to locate web element using element text

Open janne-j opened this issue 5 years ago • 1 comments

Click Link keyword is able to locate web element based on element's text. Could we make Click Button and Click Element to do the same?

Example web element: <div class="NavigationButton__Button-sc-1fg4hey-0 ekgIYM"><div class="NavigationButton__TextWrapper-sc-1fg4hey-1 ecjhSx">THE TEXT HERE</div><\div>

Could be clickable like: Click Element THE TEXT HERE

Current solution is to use xpath (standard css doesn't support finding text) like: Click Element xpath://div[contains(text(), "THE TEXT HERE")]]

Since Click Link is already finding elements internally via xpath, maybe that's doable also on Click Button & Click Element?

The reasons for the enhancement:

  • Cleaner locators (no xpath)
  • Makes it consistent with Click Link keyword

Another way to implement this enhancement would be to create new explicit locator strategy:

Strategy | Match based on | Example text | Element text | text:The text to find on web page

janne-j avatar Feb 21 '20 12:02 janne-j

What you want is possible and it would be also useful. I would go with new locator strategy because, if strategy is not provided SeleniumLibrary has default handling which can not be easily changed.

Would you be interested on providing an PR for this enhancement proposal?

aaltat avatar Feb 21 '20 19:02 aaltat