Skip to content

Commit 6ccbe0a

Browse files
committed
Updating IE driver getActiveElement command to be spec-compliant
If there is no active element, this method may now return a null results, as in compliance with the W3C WebDriver specification, which relies on the DOM definition of active element. Language bindings maintainers should take note that this is a behavior change, and that the command can now return null values. Adjust your language bindings accordingly.
1 parent 8d73e5f commit 6ccbe0a

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

cpp/iedriver/CommandHandlers/GetActiveElementCommandHandler.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ GetActiveElementCommandHandler::~GetActiveElementCommandHandler(void) {
2929
}
3030

3131
void GetActiveElementCommandHandler::ExecuteInternal(
32-
const IECommandExecutor& executor,
33-
const ParametersMap& command_parameters,
34-
Response* response) {
32+
const IECommandExecutor& executor,
33+
const ParametersMap& command_parameters,
34+
Response* response) {
3535
BrowserHandle browser_wrapper;
3636
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
3737
if (status_code != WD_SUCCESS) {
@@ -46,24 +46,27 @@ void GetActiveElementCommandHandler::ExecuteInternal(
4646
return;
4747
}
4848

49-
CComPtr<IHTMLElement> element;
50-
doc->get_activeElement(&element);
49+
CComPtr<IHTMLElement> element(NULL);
50+
HRESULT hr = doc->get_activeElement(&element);
5151

52-
// For some contentEditable frames, the <body> element will be the
53-
// active element. However, to properly have focus, we must explicitly
54-
// set focus to the element.
55-
CComPtr<IHTMLBodyElement> body_element;
56-
HRESULT body_hr = element->QueryInterface<IHTMLBodyElement>(&body_element);
57-
if (body_element) {
58-
CComPtr<IHTMLElement2> body_element2;
59-
body_element->QueryInterface<IHTMLElement2>(&body_element2);
60-
body_element2->focus();
52+
if (FAILED(hr)) {
53+
// For some contentEditable frames, the <body> element will be the
54+
// active element. However, to properly have focus, we must explicitly
55+
// set focus to the element.
56+
CComPtr<IHTMLBodyElement> body_element;
57+
HRESULT body_hr = element->QueryInterface<IHTMLBodyElement>(&body_element);
58+
if (body_element) {
59+
CComPtr<IHTMLElement2> body_element2;
60+
body_element->QueryInterface<IHTMLElement2>(&body_element2);
61+
body_element2->focus();
62+
}
6163
}
6264

63-
// If we don't have an element at this point, just return the
64-
// body element so that we don't return a NULL pointer.
65+
// If we don't have an element at this point, we should return a
66+
// null result, as that's what document.activeElement() returns.
6567
if (!element) {
66-
doc->get_body(&element);
68+
response->SetSuccessResponse(Json::Value::null);
69+
return;
6770
}
6871

6972
if (element) {

0 commit comments

Comments
 (0)