Skip to content

Commit 3e66e12

Browse files
committed
Updating IE driver alert detection to get alert text from "repeat" alerts
This commit should allow the proper retrieval of alert text from IE alerts that happen "repeatedly." That is, those that have the checkbox stating "Do not let this page create any more alerts." Unlike standard Windows alerts, these use controls that are only available via Active Accessibility to retrieve the text. The driver now is able to detect and retrieve text from these types of alerts.
1 parent 982d79d commit 3e66e12

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

cpp/iedriver/Alert.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ std::string Alert::GetText() {
153153
} else {
154154
std::string alert_text = this->GetDirectUIDialogText();
155155
if (!this->is_security_alert_) {
156-
size_t first_crlf = alert_text.find("\r\n\r\n");
157-
if (first_crlf != std::string::npos && first_crlf + 4 < alert_text.size()) {
158-
alert_text_value = alert_text.substr(first_crlf + 4);
156+
if (!this->is_standard_alert_) {
157+
// This means the alert is from onbeforeunload, and we need to
158+
// strip off everything up to and including the first CR-LF pair.
159+
size_t first_crlf = alert_text.find("\r\n\r\n");
160+
if (first_crlf != std::string::npos && first_crlf + 4 < alert_text.size()) {
161+
alert_text_value = alert_text.substr(first_crlf + 4);
162+
}
163+
} else {
164+
alert_text_value = alert_text;
159165
}
160166
}
161167
}
@@ -240,12 +246,18 @@ std::string Alert::GetDirectUIDialogText() {
240246
return alert_text_value;
241247
}
242248

243-
// ASSUMPTION: The second "static text" accessibility object is the one
244-
// that contains the message.
249+
int child_index = 0;
250+
if (!this->is_standard_alert_) {
251+
// ASSUMPTION: This means the alert is from onbeforeunload, and
252+
// the second "static text" accessibility object is the one
253+
// that contains the message.
254+
child_index = 1;
255+
}
256+
245257
CComPtr<IAccessible> message_text_object = this->GetChildWithRole(
246258
pane_object,
247259
ROLE_SYSTEM_STATICTEXT,
248-
1);
260+
child_index);
249261
if (!message_text_object) {
250262
LOG(WARN) << "Failed to get Active Accessibility text child object from pane";
251263
return alert_text_value;

0 commit comments

Comments
 (0)