Skip to content

Commit d25d966

Browse files
committed
Updating IE driver atoms to properly return element position
A recent update to the Closure compiler caused a regression in the IE driver as it was more aggressive about renaming properties of returned objects than previous versions. This commit adds a custom IE-only atom that avoids this behavior of the compiler, and lets the driver properly return an element's location. Fixes issue #4480.
1 parent 9a4f5fd commit d25d966

File tree

4 files changed

+503
-129
lines changed

4 files changed

+503
-129
lines changed

cpp/iedriver/CommandHandlers/GetElementRectCommandHandler.cpp

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,71 +58,47 @@ void GetElementRectCommandHandler::ExecuteInternal(
5858
// Furthermore, we need to invoke the function that is the atom and
5959
// get the result, but we need to wrap the execution in another function
6060
// so that it can be invoked without polluting the current namespace.
61-
std::wstring script_source = L"(function() { return function() { var result = ";
62-
script_source += L"(function() { return (";
63-
script_source += atoms::asString(atoms::GET_SIZE);
64-
script_source += L")})().apply(null, arguments);";
65-
script_source += L"return [result.width, result.height]; };})();";
61+
std::wstring script_source(L"(function() { return (");
62+
script_source += atoms::asString(atoms::GET_ELEMENT_RECT);
63+
script_source += L")})();";
6664

6765
CComPtr<IHTMLDocument2> doc;
6866
browser_wrapper->GetDocument(&doc);
6967

70-
Json::Value size_array;
68+
Json::Value rect_object;
7169
Script script_wrapper(doc, script_source, 1);
7270
script_wrapper.AddArgument(element_wrapper);
7371
status_code = script_wrapper.Execute();
7472

7573
if (status_code == WD_SUCCESS) {
76-
script_wrapper.ConvertResultToJsonValue(executor, &size_array);
74+
script_wrapper.ConvertResultToJsonValue(executor, &rect_object);
7775

78-
Json::UInt index = 0;
7976
Json::Value response_value;
80-
response_value["width"] = size_array[index];
81-
++index;
82-
response_value["height"] = size_array[index];
83-
84-
script_source = L"(function() { return function() { var result = ";
85-
script_source += L"(function() { return (";
86-
script_source += atoms::asString(atoms::GET_LOCATION);
87-
script_source += L")})().apply(null, arguments);";
88-
script_source += L"return [result.x, result.y]; };})();";
89-
90-
Json::Value location_array;
91-
Script location_script_wrapper(doc, script_source, 1);
92-
location_script_wrapper.AddArgument(element_wrapper);
93-
status_code = location_script_wrapper.Execute();
94-
95-
if (status_code == WD_SUCCESS) {
96-
location_script_wrapper.ConvertResultToJsonValue(executor, &location_array);
97-
Json::UInt index = 0;
98-
int x = location_array.get(index, 0).asInt();
99-
++index;
100-
int y = location_array.get(index, 0).asInt();
101-
102-
CComPtr<IHTMLDocument2> doc;
103-
browser_wrapper->GetDocument(&doc);
104-
int browser_version = executor.browser_factory()->browser_version();
105-
bool browser_appears_before_ie8 = browser_version < 8 || DocumentHost::GetDocumentMode(doc) <= 7;
106-
bool is_quirks_mode = !DocumentHost::IsStandardsMode(doc);
107-
if (browser_appears_before_ie8 && !is_quirks_mode) {
108-
// NOTE: For IE 6 and 7 in standards mode, elements with "display:none"
109-
// in the CSS style should have a 2-pixel offset for their location.
110-
std::string display_value = "";
111-
element_wrapper->GetCssPropertyValue("display", &display_value);
112-
if (display_value == "none") {
113-
int offset = 2;
114-
x += offset;
115-
y += offset;
116-
}
77+
response_value["width"] = rect_object["width"];
78+
response_value["height"] = rect_object["height"];
79+
80+
int x = rect_object.get("x", 0).asInt();
81+
int y = rect_object.get("y", 0).asInt();
82+
83+
int browser_version = executor.browser_factory()->browser_version();
84+
bool browser_appears_before_ie8 = browser_version < 8 || DocumentHost::GetDocumentMode(doc) <= 7;
85+
bool is_quirks_mode = !DocumentHost::IsStandardsMode(doc);
86+
if (browser_appears_before_ie8 && !is_quirks_mode) {
87+
// NOTE: For IE 6 and 7 in standards mode, elements with "display:none"
88+
// in the CSS style should have a 2-pixel offset for their location.
89+
std::string display_value = "";
90+
element_wrapper->GetCssPropertyValue("display", &display_value);
91+
if (display_value == "none") {
92+
int offset = 2;
93+
x += offset;
94+
y += offset;
11795
}
118-
119-
response_value["x"] = x;
120-
response_value["y"] = y;
121-
response->SetSuccessResponse(response_value);
122-
return;
123-
} else {
124-
response->SetErrorResponse(status_code, "Unable to get element location");
12596
}
97+
98+
response_value["x"] = x;
99+
response_value["y"] = y;
100+
response->SetSuccessResponse(response_value);
101+
return;
126102
} else {
127103
response->SetErrorResponse(status_code, "Unable to get element sizes");
128104
return;

0 commit comments

Comments
 (0)