本文整理汇总了C++中ParametersMap::find方法的典型用法代码示例。如果您正苦于以下问题:C++ ParametersMap::find方法的具体用法?C++ ParametersMap::find怎么用?C++ ParametersMap::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParametersMap
的用法示例。
在下文中一共展示了ParametersMap::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteInternal
void SetTimeoutCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator type_parameter_iterator = command_parameters.find("type");
ParametersMap::const_iterator ms_parameter_iterator = command_parameters.find("ms");
if (type_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: type");
return;
} else if (ms_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: ms");
return;
} else {
std::string timeout_type = type_parameter_iterator->second.asString();
int timeout = ms_parameter_iterator->second.asInt();
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
if (timeout_type == "implicit") {
mutable_executor.set_implicit_wait_timeout(timeout);
} else if (timeout_type == "script") {
mutable_executor.set_async_script_timeout(timeout);
} else if (timeout_type == "page load") {
mutable_executor.set_page_load_timeout(timeout);
} else {
response->SetErrorResponse(EUNHANDLEDERROR, "Invalid timeout type specified: " + timeout_type);
return;
}
response->SetSuccessResponse(Json::Value::null);
}
}
示例2: ExecuteInternal
void GetElementPropertyCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
ParametersMap::const_iterator name_parameter_iterator = command_parameters.find("name");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else if (name_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: name");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
std::string name = name_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
std::string value = "";
bool is_null;
status_code = element_wrapper->GetPropertyValue(name,
&value,
&is_null);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get property");
return;
} else {
if (is_null) {
response->SetSuccessResponse(Json::Value::null);
return;
} else {
response->SetSuccessResponse(value);
return;
}
}
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例3: ExecuteInternal
void SetWindowPositionCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("windowHandle");
ParametersMap::const_iterator x_parameter_iterator = command_parameters.find("x");
ParametersMap::const_iterator y_parameter_iterator = command_parameters.find("y");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter in URL: windowHandle");
return;
} else if (x_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: x");
return;
} else if (y_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: y");
return;
} else {
int status_code = WD_SUCCESS;
int x = x_parameter_iterator->second.asInt();
int y = y_parameter_iterator->second.asInt();
std::string window_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
if (window_id == "current") {
status_code = executor.GetCurrentBrowser(&browser_wrapper);
} else {
status_code = executor.GetManagedBrowser(window_id, &browser_wrapper);
}
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Error retrieving window with handle " + window_id);
return;
}
HWND window_handle = browser_wrapper->GetTopLevelWindowHandle();
POINT desired_location;
desired_location.x = x;
desired_location.y = y;
BOOL set_window_pos_result = ::SetWindowPos(window_handle, NULL, desired_location.x, desired_location.y, 0, 0, SWP_NOSIZE);
if (!set_window_pos_result) {
response->SetErrorResponse(EUNHANDLEDERROR,
"Unexpected error setting window size (SetWindowPos API failed)");
return;
}
response->SetSuccessResponse(Json::Value::null);
}
}
示例4: ExecuteInternal
void DeleteCookieCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator name_parameter_iterator = command_parameters.find("name");
if (name_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: name");
return;
}
std::string cookie_name = name_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
BrowserCookie cookie;
cookie.set_name(cookie_name);
browser_wrapper->cookie_manager()->DeleteCookie(
browser_wrapper->GetCurrentUrl(),
cookie);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to delete cookie");
return;
}
response->SetSuccessResponse(Json::Value::null);
}
示例5: ExecuteInternal
void ActionsCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get current browser");
return;
}
ParametersMap::const_iterator actions_parameter_iterator = command_parameters.find("actions");
if (actions_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: actions");
return;
}
if (!actions_parameter_iterator->second.isArray()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Actions value is not an array");
return;
}
std::string error_info = "";
status_code = executor.input_manager()->PerformInputSequence(browser_wrapper,
actions_parameter_iterator->second,
&error_info);
if (status_code != WD_SUCCESS) {
if (status_code == EMOVETARGETOUTOFBOUNDS) {
response->SetErrorResponse(status_code, error_info);
} else {
response->SetErrorResponse(status_code, "Unexpected error performing action sequence.");
}
return;
}
response->SetSuccessResponse(Json::Value::null);
}
示例6: ExecuteInternal
void IsElementSelectedCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
bool is_selected = element_wrapper->IsSelected();
response->SetSuccessResponse(is_selected);
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例7: parseParameters
void BayesFilter::parseParameters(const ParametersMap & parameters)
{
ParametersMap::const_iterator iter;
if((iter=parameters.find(Parameters::kBayesVirtualPlacePriorThr())) != parameters.end())
{
this->setVirtualPlacePrior(std::atof((*iter).second.c_str()));
}
if((iter=parameters.find(Parameters::kBayesPredictionLC())) != parameters.end())
{
this->setPredictionLC((*iter).second);
}
if((iter=parameters.find(Parameters::kBayesFullPredictionUpdate())) != parameters.end())
{
_fullPredictionUpdate = uStr2Bool((*iter).second.c_str());
}
}
示例8: ExecuteInternal
void GetElementTextCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else {
std::string element_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
// The atom is just the definition of an anonymous
// function: "function() {...}"; Wrap it in another function so
// we can invoke it with our arguments without polluting the
// current namespace.
std::wstring script_source = L"(function() { return (";
script_source += atoms::asString(atoms::GET_TEXT);
script_source += L")})();";
CComPtr<IHTMLDocument2> doc;
browser_wrapper->GetDocument(&doc);
Script script_wrapper(doc, script_source, 1);
script_wrapper.AddArgument(element_wrapper->element());
status_code = script_wrapper.Execute();
if (status_code == WD_SUCCESS) {
std::string text = "";
bool is_null = script_wrapper.ConvertResultToString(&text);
response->SetSuccessResponse(text);
return;
} else {
response->SetErrorResponse(status_code,
"Unable to get element text");
return;
}
} else {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE, "Element is no longer valid");
return;
}
}
}
示例9: parseParameters
void Camera::parseParameters(const ParametersMap & parameters)
{
UDEBUG("");
ParametersMap::const_iterator iter;
//Keypoint detector
KeypointDetector::DetectorType detector = KeypointDetector::kDetectorUndef;
if((iter=parameters.find(Parameters::kKpDetectorStrategy())) != parameters.end())
{
detector = (KeypointDetector::DetectorType)std::atoi((*iter).second.c_str());
}
if(detector!=KeypointDetector::kDetectorUndef)
{
ULOGGER_DEBUG("new detector strategy %d", int(detector));
if(_keypointDetector)
{
delete _keypointDetector;
_keypointDetector = 0;
}
if(_keypointDescriptor)
{
delete _keypointDescriptor;
_keypointDescriptor = 0;
}
switch(detector)
{
case KeypointDetector::kDetectorSift:
_keypointDetector = new SIFTDetector(parameters);
_keypointDescriptor = new SIFTDescriptor(parameters);
break;
case KeypointDetector::kDetectorSurf:
default:
_keypointDetector = new SURFDetector(parameters);
_keypointDescriptor = new SURFDescriptor(parameters);
break;
}
}
else
{
if(_keypointDetector)
{
_keypointDetector->parseParameters(parameters);
}
if(_keypointDescriptor)
{
_keypointDescriptor->parseParameters(parameters);
}
}
}
示例10: GetNumericParameter
bool SetWindowRectCommandHandler::GetNumericParameter(
const ParametersMap& command_parameters,
const std::string& argument_name,
int* argument_value,
std::string* error_message) {
ParametersMap::const_iterator parameter_iterator = command_parameters.find(argument_name);
if (parameter_iterator != command_parameters.end()) {
if (!parameter_iterator->second.isNumeric()) {
*error_message = argument_name + " must be a numeric parameter.";
return false;
}
int value = parameter_iterator->second.asInt();
if (value < 0) {
*error_message = argument_name + " must be a numeric parameter greater than zero.";
return false;
}
*argument_value = value;
return true;
}
return true;
}
示例11: ExecuteInternal
void ExecuteAsyncScriptCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator script_parameter_iterator = command_parameters.find("script");
ParametersMap::const_iterator args_parameter_iterator = command_parameters.find("args");
if (script_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: script");
return;
} else if (args_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: args");
return;
} else {
wchar_t page_id_buffer[GUID_STRING_LEN] = {0};
GUID page_id_guid;
::CoCreateGuid(&page_id_guid);
::StringFromGUID2(page_id_guid, page_id_buffer, GUID_STRING_LEN);
std::wstring page_id = &page_id_buffer[0];
wchar_t pending_id_buffer[GUID_STRING_LEN] = {0};
GUID pending_id_guid;
::CoCreateGuid(&pending_id_guid);
::StringFromGUID2(pending_id_guid, pending_id_buffer, GUID_STRING_LEN);
std::wstring pending_id = &pending_id_buffer[0];
Json::Value json_args = args_parameter_iterator->second;
int timeout_value = executor.async_script_timeout();
std::wstring timeout = std::to_wstring(static_cast<long long>(timeout_value));
std::wstring script_body = StringUtilities::ToWString(script_parameter_iterator->second.asString());
std::wstring async_script = L"(function() { return function(){\n";
async_script += L"document.__$webdriverAsyncExecutor = {\n";
async_script += L" pageId: '" + page_id + L"',\n";
async_script += L" asyncTimeout: 0\n";
async_script += L"};\n";
async_script += L"var timeoutId = window.setTimeout(function() {\n";
async_script += L" window.setTimeout(function() {\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncTimeout = 1;\n";
async_script += L" }, 0);\n";
async_script += L"}," + timeout + L");\n";
async_script += L"var callback = function(value) {\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncTimeout = 0;\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncScriptResult = value;\n";
async_script += L" window.clearTimeout(timeoutId);\n";
async_script += L"};\n";
async_script += L"var argsArray = Array.prototype.slice.call(arguments);\n";
async_script += L"argsArray.push(callback);\n";
async_script += L"if (document.__$webdriverAsyncExecutor.asyncScriptResult !== undefined) {\n";
async_script += L" delete document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
async_script += L"}\n";
async_script += L"(function() {" + script_body + L"}).apply(null, argsArray);\n";
async_script += L"};})();";
std::wstring polling_script = L"(function() { return function(){\n";
polling_script += L"var pendingId = '" + pending_id + L"';\n";
polling_script += L"if ('__$webdriverAsyncExecutor' in document) {\n";
polling_script += L" if (document.__$webdriverAsyncExecutor.pageId != '" + page_id + L"') {\n";
polling_script += L" return [pendingId, -1];\n";
polling_script += L" } else if ('asyncScriptResult' in document.__$webdriverAsyncExecutor) {\n";
polling_script += L" var value = document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
polling_script += L" delete document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
polling_script += L" return value;\n";
polling_script += L" } else {\n";
polling_script += L" return [pendingId, document.__$webdriverAsyncExecutor.asyncTimeout];\n";
polling_script += L" }\n";
polling_script += L"} else {\n";
polling_script += L" return [pendingId, -1];\n";
polling_script += L"}\n";
polling_script += L"};})();";
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
CComPtr<IHTMLDocument2> doc;
browser_wrapper->GetDocument(&doc);
Script async_script_wrapper(doc, async_script, json_args.size());
status_code = this->PopulateArgumentArray(executor,
async_script_wrapper,
json_args);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code,
"Error setting arguments for script");
return;
}
status_code = async_script_wrapper.Execute();
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code,
"JavaScript error in async script.");
return;
} else {
Script polling_script_wrapper(doc, polling_script, 0);
while (true) {
//.........这里部分代码省略.........
示例12: ExecuteInternal
void ExecuteAsyncScriptCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator script_parameter_iterator = command_parameters.find("script");
ParametersMap::const_iterator args_parameter_iterator = command_parameters.find("args");
if (script_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
"Missing parameter: script");
return;
}
if (!script_parameter_iterator->second.isString()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
"script parameter must be a string");
return;
}
if (args_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
"Missing parameter: args");
return;
}
if (!args_parameter_iterator->second.isArray()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
"args parameter must be an array");
return;
}
std::vector<wchar_t> page_id_buffer(GUID_STRING_LEN);
GUID page_id_guid;
::CoCreateGuid(&page_id_guid);
::StringFromGUID2(page_id_guid, &page_id_buffer[0], GUID_STRING_LEN);
std::wstring page_id = &page_id_buffer[0];
std::vector<wchar_t> pending_id_buffer(GUID_STRING_LEN);
GUID pending_id_guid;
::CoCreateGuid(&pending_id_guid);
::StringFromGUID2(pending_id_guid, &pending_id_buffer[0], GUID_STRING_LEN);
std::wstring pending_id = &pending_id_buffer[0];
Json::Value json_args = args_parameter_iterator->second;
unsigned long long timeout_value = executor.async_script_timeout();
std::wstring timeout = std::to_wstring(static_cast<long long>(timeout_value));
std::wstring script_body = StringUtilities::ToWString(script_parameter_iterator->second.asString());
std::wstring async_script = L"(function() { return function(){\n";
async_script += L"document.__$webdriverAsyncExecutor = {\n";
async_script += L" pageId: '" + page_id + L"',\n";
async_script += L" asyncTimeout: 0\n";
async_script += L"};\n";
async_script += L"var timeoutId = window.setTimeout(function() {\n";
async_script += L" window.setTimeout(function() {\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncTimeout = 1;\n";
async_script += L" }, 0);\n";
async_script += L"}," + timeout + L");\n";
async_script += L"var callback = function(value) {\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncTimeout = 0;\n";
async_script += L" document.__$webdriverAsyncExecutor.asyncScriptResult = value;\n";
async_script += L" window.clearTimeout(timeoutId);\n";
async_script += L"};\n";
async_script += L"var argsArray = Array.prototype.slice.call(arguments);\n";
async_script += L"argsArray.push(callback);\n";
async_script += L"if (document.__$webdriverAsyncExecutor.asyncScriptResult !== undefined) {\n";
async_script += L" delete document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
async_script += L"}\n";
async_script += L"(function() {\n" + script_body + L"\n}).apply(null, argsArray);\n";
async_script += L"};})();";
std::wstring polling_script = L"(function() { return function(){\n";
polling_script += L"var pendingId = '" + pending_id + L"';\n";
polling_script += L"if ('__$webdriverAsyncExecutor' in document) {\n";
polling_script += L" if (document.__$webdriverAsyncExecutor.pageId != '" + page_id + L"') {\n";
polling_script += L" return {'status': 'reload', 'id': pendingId, 'value': -1};\n";
polling_script += L" } else if ('asyncScriptResult' in document.__$webdriverAsyncExecutor) {\n";
polling_script += L" var value = document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
polling_script += L" delete document.__$webdriverAsyncExecutor.asyncScriptResult;\n";
polling_script += L" return {'status': 'complete', 'id': pendingId, 'value': value};\n";
polling_script += L" } else if (document.__$webdriverAsyncExecutor.asyncTimeout == 0) {\n";
polling_script += L" return {'status': 'pending', 'id': pendingId, 'value': document.__$webdriverAsyncExecutor.asyncTimeout};\n";
polling_script += L" } else {\n";
polling_script += L" return {'status': 'timeout', 'id': pendingId, 'value': document.__$webdriverAsyncExecutor.asyncTimeout};\n";
polling_script += L" }\n";
polling_script += L"} else {\n";
polling_script += L" return {'status': 'reload', 'id': pendingId, 'value': -1};\n";
polling_script += L"}\n";
polling_script += L"};})();";
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
CComPtr<IHTMLDocument2> doc;
browser_wrapper->GetDocument(&doc);
//.........这里部分代码省略.........
示例13: ExecuteInternal
void FindChildElementsCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
ParametersMap::const_iterator using_parameter_iterator = command_parameters.find("using");
ParametersMap::const_iterator value_parameter_iterator = command_parameters.find("value");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
}
if (using_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: using");
return;
}
if (!using_parameter_iterator->second.isString()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "using parameter must be a string");
return;
}
if (value_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: value");
return;
}
if (!value_parameter_iterator->second.isString()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "value parameter must be a string");
return;
}
std::string mechanism = using_parameter_iterator->second.asString();
std::string value = value_parameter_iterator->second.asString();
std::string element_id = id_parameter_iterator->second.asString();
if (mechanism != "css selector" &&
mechanism != "tag name" &&
mechanism != "link text" &&
mechanism != "partial link text" &&
mechanism != "xpath") {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "using parameter value '" + mechanism + "' is not a valid value");
return;
}
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Currently focused window has been closed.");
return;
}
ElementHandle parent_element_wrapper;
status_code = this->GetElement(executor,
element_id,
&parent_element_wrapper);
if (status_code == WD_SUCCESS) {
Json::Value found_elements(Json::arrayValue);
int timeout = static_cast<int>(executor.implicit_wait_timeout());
clock_t end = clock() + (timeout / 1000 * CLOCKS_PER_SEC);
if (timeout > 0 && timeout < 1000) {
end += 1 * CLOCKS_PER_SEC;
}
do {
status_code = executor.LocateElements(parent_element_wrapper,
mechanism,
value,
&found_elements);
if (status_code == WD_SUCCESS) {
if (found_elements.isArray() && found_elements.size() > 0) {
response->SetSuccessResponse(found_elements);
return;
}
} else if (status_code == ENOSUCHWINDOW) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW,
"Unable to find elements on closed window");
return;
} else {
response->SetErrorResponse(status_code, found_elements.asString());
return;
}
// Release the thread so that the browser doesn't starve.
::Sleep(FIND_ELEMENT_WAIT_TIME_IN_MILLISECONDS);
} while (clock() < end);
// This code is executed when no elements where found and no errors occurred.
if (status_code == WD_SUCCESS) {
response->SetSuccessResponse(found_elements);
} else {
response->SetErrorResponse(status_code,
"Finding elements with " + mechanism + " == " + value +
"returned an unexpected error");
}
} else {
if (status_code == EOBSOLETEELEMENT) {
response->SetErrorResponse(ERROR_STALE_ELEMENT_REFERENCE,
"Specified parent element is no longer attached to the DOM");
} else {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT,
"Element is no longer valid");
//.........这里部分代码省略.........
示例14: ExecuteInternal
void ClickElementCommandHandler::ExecuteInternal(const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");
if (id_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");
return;
} else {
int status_code = WD_SUCCESS;
std::string element_id = id_parameter_iterator->second.asString();
BrowserHandle browser_wrapper;
status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
ElementHandle element_wrapper;
status_code = this->GetElement(executor, element_id, &element_wrapper);
if (status_code == WD_SUCCESS) {
if (executor.input_manager()->enable_native_events()) {
if (this->IsOptionElement(element_wrapper)) {
std::string option_click_error = "";
status_code = this->ExecuteAtom(this->GetClickAtom(),
browser_wrapper,
element_wrapper,
&option_click_error);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Cannot click on option element. " + option_click_error);
return;
}
} else {
Json::Value move_action;
move_action["type"] = "pointerMove";
move_action["origin"] = element_wrapper->ConvertToJson();
move_action["duration"] = 0;
Json::Value down_action;
down_action["type"] = "pointerDown";
down_action["button"] = 0;
Json::Value up_action;
up_action["type"] = "pointerUp";
up_action["button"] = 0;
Json::Value action_array(Json::arrayValue);
action_array.append(move_action);
action_array.append(down_action);
action_array.append(up_action);
// Check to make sure we're not within the double-click time for this element
// since the last click.
int double_click_time = ::GetDoubleClickTime();
Json::Value parameters_value;
parameters_value["pointerType"] = "mouse";
Json::Value value;
value["type"] = "pointer";
value["id"] = "click action mouse";
value["parameters"] = parameters_value;
value["actions"] = action_array;
Json::Value actions(Json::arrayValue);
actions.append(value);
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
status_code = mutable_executor.input_manager()->PerformInputSequence(browser_wrapper, actions);
browser_wrapper->set_wait_required(true);
::Sleep(double_click_time + 10);
if (status_code != WD_SUCCESS) {
if (status_code == EELEMENTCLICKPOINTNOTSCROLLED) {
// We hard-code the error code here to be "Element not visible"
// to maintain compatibility with previous behavior.
response->SetErrorResponse(ERROR_ELEMENT_NOT_INTERACTABLE, "The point at which the driver is attempting to click on the element was not scrolled into the viewport.");
} else {
response->SetErrorResponse(status_code, "Cannot click on element");
}
return;
}
}
} else {
bool displayed;
status_code = element_wrapper->IsDisplayed(true, &displayed);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to determine element is displayed");
return;
}
if (!displayed) {
response->SetErrorResponse(ERROR_ELEMENT_NOT_INTERACTABLE, "Element is not displayed");
return;
}
std::string synthetic_click_error = "";
status_code = this->ExecuteAtom(this->GetSyntheticClickAtom(),
browser_wrapper,
element_wrapper,
&synthetic_click_error);
if (status_code != WD_SUCCESS) {
//.........这里部分代码省略.........
示例15: ExecuteInternal
void FindElementCommandHandler::ExecuteInternal(
const IECommandExecutor& executor,
const ParametersMap& command_parameters,
Response* response) {
ParametersMap::const_iterator using_parameter_iterator = command_parameters.find("using");
ParametersMap::const_iterator value_parameter_iterator = command_parameters.find("value");
if (using_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: using");
return;
}
if (!using_parameter_iterator->second.isString()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "using parameter must be a string");
return;
}
if (value_parameter_iterator == command_parameters.end()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: value");
return;
}
if (!value_parameter_iterator->second.isString()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "value parameter must be a string");
return;
}
std::string mechanism = using_parameter_iterator->second.asString();
std::string value = value_parameter_iterator->second.asString();
if (mechanism != "css selector" &&
mechanism != "tag name" &&
mechanism != "link text" &&
mechanism != "partial link text" &&
mechanism != "xpath") {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "using parameter value '" + mechanism + "' is not a valid value");
return;
}
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Currently focused window has been closed.");
return;
}
int timeout = static_cast<int>(executor.implicit_wait_timeout());
clock_t end = clock() + (timeout / 1000 * CLOCKS_PER_SEC);
if (timeout > 0 && timeout < 1000) {
end += 1 * CLOCKS_PER_SEC;
}
status_code = WD_SUCCESS;
Json::Value found_element;
do {
status_code = executor.LocateElement(ElementHandle(),
mechanism,
value,
&found_element);
if (status_code == WD_SUCCESS) {
response->SetSuccessResponse(found_element);
return;
}
if (status_code == ENOSUCHWINDOW) {
response->SetErrorResponse(ERROR_NO_SUCH_WINDOW, "Unable to find element on closed window");
return;
}
if (status_code != ENOSUCHELEMENT) {
response->SetErrorResponse(status_code, found_element.asString());
return;
}
// Release the thread so that the browser doesn't starve.
::Sleep(FIND_ELEMENT_WAIT_TIME_IN_MILLISECONDS);
} while (clock() < end);
response->SetErrorResponse(ERROR_NO_SUCH_ELEMENT,
"Unable to find element with " + mechanism + " == " + value);
return;
}