Skip to content

Commit

Permalink
Updating IE driver alert detection to get alert text from "repeat" al…
Browse files Browse the repository at this point in the history
…erts

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.
  • Loading branch information
jimevans committed Feb 2, 2018
1 parent 982d79d commit 3e66e12
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cpp/iedriver/Alert.cpp
Expand Up @@ -153,9 +153,15 @@ std::string Alert::GetText() {
} else {
std::string alert_text = this->GetDirectUIDialogText();
if (!this->is_security_alert_) {
size_t first_crlf = alert_text.find("\r\n\r\n");
if (first_crlf != std::string::npos && first_crlf + 4 < alert_text.size()) {
alert_text_value = alert_text.substr(first_crlf + 4);
if (!this->is_standard_alert_) {
// This means the alert is from onbeforeunload, and we need to
// strip off everything up to and including the first CR-LF pair.
size_t first_crlf = alert_text.find("\r\n\r\n");
if (first_crlf != std::string::npos && first_crlf + 4 < alert_text.size()) {
alert_text_value = alert_text.substr(first_crlf + 4);
}
} else {
alert_text_value = alert_text;
}
}
}
Expand Down Expand Up @@ -240,12 +246,18 @@ std::string Alert::GetDirectUIDialogText() {
return alert_text_value;
}

// ASSUMPTION: The second "static text" accessibility object is the one
// that contains the message.
int child_index = 0;
if (!this->is_standard_alert_) {
// ASSUMPTION: This means the alert is from onbeforeunload, and
// the second "static text" accessibility object is the one
// that contains the message.
child_index = 1;
}

CComPtr<IAccessible> message_text_object = this->GetChildWithRole(
pane_object,
ROLE_SYSTEM_STATICTEXT,
1);
child_index);
if (!message_text_object) {
LOG(WARN) << "Failed to get Active Accessibility text child object from pane";
return alert_text_value;
Expand Down

0 comments on commit 3e66e12

Please sign in to comment.