diff --git a/detox/ios/Detox/Invocation/WebCodeBuilder+createMoveCursorToEndAction.swift b/detox/ios/Detox/Invocation/WebCodeBuilder+createMoveCursorToEndAction.swift index 69ef8d1d94..cba838f62b 100644 --- a/detox/ios/Detox/Invocation/WebCodeBuilder+createMoveCursorToEndAction.swift +++ b/detox/ios/Detox/Invocation/WebCodeBuilder+createMoveCursorToEndAction.swift @@ -27,17 +27,21 @@ extension WebCodeBuilder { } }; + if (document.activeElement !== element) { + element.focus(); + } if (typeof element.setSelectionRange === 'function') { - const length = getLength(element); - - /* This is a workaround. See: https://w3.org/Bugs/Public/show_bug.cgi?id=24796 */ - const originalType = element.getAttribute('type'); - element.setAttribute('type', 'text'); + if (element.nodeName.toLowerCase() === 'input' && + ['text', 'search', 'tel', 'url', 'password'].includes(element.type.toLowerCase()) === false) { + /* Some input types do not support `setSelectionRange`. See: + * https://html.spec.whatwg.org/multipage/input.html#:~:text=%C2%B7-,setSelectionRange(),-%C2%B7 + */ + return; + } + const length = getLength(element); element.setSelectionRange(length, length); - - element.setAttribute('type', originalType); } else { var range = element.ownerDocument.createRange();