element icon indicating copy to clipboard operation
element copied to clipboard

Ability to combine locators

Open mrvdot opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe. Often I want to select an item from a list of very similar items, but searching just by text is not effective (e.g. I have both the button I want to click and the title of a "details" view with the same text).

Describe the solution you'd like It would be helpful to be able to chain/combine locators, so I can search by multiple types, (i.e. CSS and text or tag and className), such as By.css('.item-selector').visibleText('My Item')

Describe alternatives you've considered As best as I can see, the only alternative is to select all elements that match .item-selector and then loop checking the text of each until I find the current ElementHandle

mrvdot avatar Dec 23 '20 22:12 mrvdot

If you want to find a unique locator, may I recommend ChroPath as a tool? Would also suggest that CSS and XPATH already supports multiple attributes eg for CSS: "div[class='ajax_enabled'] [style='display:block']" (so two sets of square brackets). I suspect xpath is easier to work with text however but that is just my preference.

Danbown avatar Jul 09 '21 11:07 Danbown