Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/CommandHandlers/ElementEqualsCommandHandler.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 "ElementEqualsCommandHandler.h"
18
#include "errorcodes.h"
19
#include "../Browser.h"
20
#include "../Element.h"
21
#include "../IECommandExecutor.h"
22
23
namespace webdriver {
24
25
ElementEqualsCommandHandler::ElementEqualsCommandHandler(void) {
26
}
27
28
ElementEqualsCommandHandler::~ElementEqualsCommandHandler(void) {
29
}
30
31
void ElementEqualsCommandHandler::ExecuteInternal(
32
const IECommandExecutor& executor,
33
const ParametersMap& command_parameters,
34
Response* response) {
35
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
36
ParametersMap::const_iterator other_parameter_iterator = command_parameters.find("other");
37
if (id_parameter_iterator == command_parameters.end()) {
38
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
39
return;
40
}
41
else if (other_parameter_iterator == command_parameters.end()) {
42
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: other");
43
return;
44
} else {
45
std::string element_id = id_parameter_iterator->second.asString();
46
std::string other_element_id = other_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
55
ElementHandle element_wrapper;
56
status_code = this->GetElement(executor, element_id, &element_wrapper);
57
if (status_code == WD_SUCCESS)
58
{
59
ElementHandle other_element_wrapper;
60
status_code = this->GetElement(executor,
61
other_element_id,
62
&other_element_wrapper);
63
if (status_code == WD_SUCCESS) {
64
response->SetSuccessResponse((element_wrapper->element() == other_element_wrapper->element()));
65
return;
66
} else {
67
response->SetErrorResponse(status_code,
68
"Element specified by 'other' is no longer valid");
69
return;
70
}
71
} else {
72
response->SetErrorResponse(status_code,
73
"Element specified by 'id' is no longer valid");
74
return;
75
}
76
}
77
78
}
79
80
} // namespace webdriver
81
82