interactors icon indicating copy to clipboard operation
interactors copied to clipboard

Trim selector text by default?

Open cowboyd opened this issue 3 years ago • 3 comments

Safari includes up to one newline in its innerText property for elements. Why, I'm not sure, but it ends up that you don't match your selectors on different platforms:

image showing search for selector DEFAULT, but no match because the actual selector is DEFAULT + newline

Should we trim the selector before matching against it?

cowboyd avatar Aug 30 '21 10:08 cowboyd

One posible strategy would be instead of trimming the element locator, to always wrap the locator in a matcher. The default would be trimmed, but we could also have a strictEquals locator that that did a === as its match. So that if it was what you really wanted you could match that.

cowboyd avatar Sep 21 '21 10:09 cowboyd

Ugh, this is annoying. IIRC Capybara does trim the text, which seems reasonable since whitespace is very rarely relevant in HTML documents anyway. I think the HTML interactor could do this, that way it'd still be overridable if someone really wants to.

jnicklas avatar Oct 26 '21 11:10 jnicklas

Most interactors override the locator method. So I think we should implement trimming on the internal level, like adding the special trim matcher.

wKich avatar Oct 26 '21 19:10 wKich