Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/CommandHandlers/GetAlertTextCommandHandler.cpp
2868 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "GetAlertTextCommandHandler.h"
18
#include "errorcodes.h"
19
#include "../Alert.h"
20
#include "../Browser.h"
21
#include "../IECommandExecutor.h"
22
23
namespace webdriver {
24
25
GetAlertTextCommandHandler::GetAlertTextCommandHandler(void) {
26
}
27
28
GetAlertTextCommandHandler::~GetAlertTextCommandHandler(void) {
29
}
30
31
void GetAlertTextCommandHandler::ExecuteInternal(
32
const IECommandExecutor& executor,
33
const ParametersMap& command_parameters,
34
Response* response) {
35
BrowserHandle browser_wrapper;
36
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
37
if (status_code != WD_SUCCESS) {
38
response->SetErrorResponse(status_code, "Unable to get browser");
39
return;
40
}
41
// This sleep is required to give IE time to draw the dialog.
42
::Sleep(100);
43
HWND alert_handle = browser_wrapper->GetActiveDialogWindowHandle();
44
if (alert_handle == NULL) {
45
response->SetErrorResponse(ENOSUCHALERT, "No alert is active");
46
} else {
47
Alert dialog(browser_wrapper, alert_handle);
48
std::string alert_text_value = dialog.GetText();
49
response->SetSuccessResponse(alert_text_value);
50
}
51
}
52
53
} // namespace webdriver
54
55