"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/cpp/iedriver/CommandHandlers/SendKeysToAlertCommandHandler.cpp" (17 Feb 2023, 2875 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "SendKeysToAlertCommandHandler.cpp" see the
Fossies "Dox" file reference documentation.
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 "SendKeysToAlertCommandHandler.h"
18 #include "errorcodes.h"
19 #include "../Alert.h"
20 #include "../Browser.h"
21 #include "../IECommandExecutor.h"
22
23 namespace webdriver {
24
25 SendKeysToAlertCommandHandler::SendKeysToAlertCommandHandler(void) {
26 }
27
28 SendKeysToAlertCommandHandler::~SendKeysToAlertCommandHandler(void) {
29 }
30
31 void SendKeysToAlertCommandHandler::ExecuteInternal(
32 const IECommandExecutor& executor,
33 const ParametersMap& command_parameters,
34 Response* response) {
35 ParametersMap::const_iterator text_parameter_iterator = command_parameters.find("text");
36 if (text_parameter_iterator == command_parameters.end()) {
37 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: text");
38 return;
39 }
40
41 if (!text_parameter_iterator->second.isString()) {
42 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "text must be a string");
43 return;
44 }
45
46 std::string value = text_parameter_iterator->second.asString();
47
48 BrowserHandle browser_wrapper;
49 int status_code = executor.GetCurrentBrowser(&browser_wrapper);
50 if (status_code != WD_SUCCESS) {
51 response->SetErrorResponse(status_code, "Unable to get browser");
52 return;
53 }
54 // This sleep is required to give IE time to draw the dialog.
55 ::Sleep(100);
56 HWND alert_handle = browser_wrapper->GetActiveDialogWindowHandle();
57 if (alert_handle == NULL) {
58 response->SetErrorResponse(ERROR_NO_SUCH_ALERT, "No alert is active");
59 } else {
60 Alert dialog(browser_wrapper, alert_handle);
61 status_code = dialog.SendKeys(value);
62 if (status_code != WD_SUCCESS) {
63 if (status_code == EUNSUPPORTEDOPERATION) {
64 response->SetErrorResponse(status_code,
65 "Alert was not generated by the JavaScript alert(), confirm(), or prompt() functions");
66 return;
67 }
68 response->SetErrorResponse(ERROR_ELEMENT_NOT_INTERACTABLE,
69 "Modal dialog did not have a text box - maybe it was an alert");
70 return;
71 }
72 response->SetSuccessResponse(Json::Value::null);
73 }
74 }
75
76 } // namespace webdriver