File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
src/webdriver/extension_qt Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments