Path: blob/trunk/cpp/iedriver/CommandHandlers/AcceptAlertCommandHandler.cpp
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.1516#include "AcceptAlertCommandHandler.h"17#include "errorcodes.h"18#include "../Alert.h"19#include "../Browser.h"20#include "../IECommandExecutor.h"2122namespace webdriver {2324AcceptAlertCommandHandler::AcceptAlertCommandHandler(void) {25}2627AcceptAlertCommandHandler::~AcceptAlertCommandHandler(void) {28}2930void AcceptAlertCommandHandler::ExecuteInternal(31const IECommandExecutor& executor,32const ParametersMap& command_parameters,33Response* response) {34BrowserHandle browser_wrapper;35int status_code = executor.GetCurrentBrowser(&browser_wrapper);36if (status_code != WD_SUCCESS) {37response->SetErrorResponse(status_code, "Unable to get current browser");38return;39}40// This sleep is required to give IE time to draw the dialog.41::Sleep(100);42HWND alert_handle = browser_wrapper->GetActiveDialogWindowHandle();43if (alert_handle == NULL) {44response->SetErrorResponse(ENOSUCHALERT, "No alert is active");45} else {46Alert dialog(browser_wrapper, alert_handle);47status_code = dialog.Accept();48if (status_code != WD_SUCCESS) {49response->SetErrorResponse(status_code,50"Could not find OK button");51}5253// Add sleep to give IE time to close dialog and start Navigation if it's necessary54::Sleep(100);55browser_wrapper->set_wait_required(true);5657response->SetSuccessResponse(Json::Value::null);58}59}6061} // namespace webdriver626364