MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / CreateAnonymousFunction

Method CreateAnonymousFunction

cpp/iedriver/Script.cpp:633–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

631}
632
633bool Script::CreateAnonymousFunction(VARIANT* result) {
634 LOG(TRACE) << "Entering Script::CreateAnonymousFunction";
635
636 std::wstring function_eval_script = L"window.document.__webdriver_script_fn = ";
637 function_eval_script.append(this->source_code_.c_str());
638 CComBSTR code(function_eval_script.c_str());
639 CComBSTR lang(L"JScript");
640 CComVariant exec_script_result;
641
642 CComPtr<IHTMLWindow2> window;
643 HRESULT hr = this->script_engine_host_->get_parentWindow(&window);
644 if (FAILED(hr)) {
645 LOGHR(WARN, hr) << "Unable to get parent window, call to IHTMLDocument2::get_parentWindow failed";
646 return false;
647 }
648
649 hr = window->execScript(code, lang, &exec_script_result);
650 if (FAILED(hr)) {
651 LOGHR(WARN, hr) << "Unable to execute code, call to IHTMLWindow2::execScript failed";
652 return false;
653 }
654
655 bool get_result_success = VariantUtilities::GetVariantObjectPropertyValue(
656 this->script_engine_host_,
657 L"__webdriver_script_fn",
658 result);
659 return get_result_success;
660}
661
662int Script::AddArguments(IElementManager* element_manager, const Json::Value& arguments) {
663 LOG(TRACE) << "Entering Script::AddArguments";

Callers 1

ExecuteMethod · 0.95

Calls 2

LOGClass · 0.50
appendMethod · 0.45

Tested by

no test coverage detected