Skip to content

Commit dd61210

Browse files
committed
Update IE driver to return NoSuchElement on JavaScript atom errors
Hitting a JavaScript error with the atom is an unrecoverable error. The most common case of this for IE is when there is a page refresh, navigation, or similar, and the driver is polling for element presence. The calling code can't do anything about it, so we might as well just log and return "no such element" error code. In the common case, this means that the error will be transitory, and will sort itself out once the DOM returns to normal after the page transition is completed. Note carefully that this is an extreme hack, and has the potential to be masking a very serious problem in the driver.
1 parent 8640a62 commit dd61210

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

cpp/iedriver/ElementFinder.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,20 @@ int ElementFinder::FindElement(const IECommandExecutor& executor,
7575
Json::Value atom_value = atom_result["value"];
7676
status_code = atom_status_code;
7777
*found_element = atom_result["value"];
78-
} else {
79-
*found_element = "A JavaScript error was encountered executing the findElement atom.";
78+
}
79+
else {
80+
// Hitting a JavaScript error with the atom is an unrecoverable
81+
// error. The most common case of this for IE is when there is a
82+
// page refresh, navigation, or similar, and the driver is polling
83+
// for element presence. The calling code can't do anything about
84+
// it, so we might as well just log and return the "no such element"
85+
// error code. In the common case, this means that the error will be
86+
// transitory, and will sort itself out once the DOM returns to normal
87+
// after the page transition is completed. Note carefully that this
88+
// is an extreme hack, and has the potential to be papering over a
89+
// very serious problem in the driver.
90+
status_code = ENOSUCHELEMENT;
91+
LOG(WARN) << "A JavaScript error was encountered executing the findElement atom.";
8092
}
8193
} else {
8294
LOG(WARN) << "Unable to get browser";
@@ -132,7 +144,15 @@ int ElementFinder::FindElements(const IECommandExecutor& executor,
132144
status_code = atom_status_code;
133145
*found_elements = atom_result["value"];
134146
} else {
135-
*found_elements = "A JavaScript error was encountered executing the findElements atom.";
147+
// Hitting a JavaScript error with the atom is an unrecoverable
148+
// error. The most common case of this for IE is when there is a
149+
// page refresh, navigation, or similar, and the driver is polling
150+
// for element presence. The calling code can't do anything about
151+
// it, so we might as well just log and return In the common case,
152+
// this means that the error will be transitory, and will sort
153+
// itself out once the DOM returns to normal after the page transition
154+
// is completed.
155+
LOG(WARN) << "A JavaScript error was encountered executing the findElements atom.";
136156
}
137157
} else {
138158
LOG(WARN) << "Unable to get browser";

0 commit comments

Comments
 (0)