SeleniumLibrary
SeleniumLibrary copied to clipboard
Enable Click Button and Click Element to locate web element using element text
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
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?