Skip to content

Commit 5fb1329

Browse files
author
Vasyl Vavrychuk
committed
fixed org.openqa.selenium.TypingTest.canSafelyTypeOnElementThatIsRemovedFromTheDomOnKeyPress
For this updated QWebkitProxy::SetActiveElement based on code in chromium
1 parent 9c69ef8 commit 5fb1329

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/webdriver/extension_qt/qwebkit_proxy.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ Error* QWebkitProxy::SetActiveElement(const ElementId& element) {
477477
// the body, sometimes we still need to focus the body element for send
478478
// keys to work. Not sure why
479479
// - You cannot focus a descendant of a content editable node
480+
// - V8 throws a TypeError when calling setSelectionRange for a non-text
481+
// input, which still have setSelectionRange defined. For chrome 29+, V8
482+
// throws a DOMException with code InvalidStateError.
480483
// TODO(jleyba): Update this to use the correct atom.
481484
const char* kFocusScript =
482485
"function(elem) {"
@@ -487,10 +490,16 @@ Error* QWebkitProxy::SetActiveElement(const ElementId& element) {
487490
" elem.focus();"
488491
" if (elem != prevActiveElem && elem.value && elem.value.length &&"
489492
" elem.setSelectionRange) {"
490-
" elem.setSelectionRange(elem.value.length, elem.value.length);"
493+
" try {"
494+
" elem.setSelectionRange(elem.value.length, elem.value.length);"
495+
" } catch (error) {"
496+
" if (!(error instanceof TypeError) && !(error instanceof DOMException &&"
497+
" error.code == DOMException.INVALID_STATE_ERR))"
498+
" throw error;"
499+
" }"
491500
" }"
492501
" if (elem != doc.activeElement)"
493-
" throw new Error('Failed to send keys because cannot focus element');"
502+
" throw new Error('cannot focus element');"
494503
"}";
495504
return ExecuteScriptAndParse(GetFrame(session_->current_frame()),
496505
kFocusScript,

0 commit comments

Comments
 (0)