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

Method FindElements

cpp/iedriver/ElementFinder.cpp:115–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115int ElementFinder::FindElements(const IECommandExecutor& executor,
116 const ElementHandle parent_wrapper,
117 const std::wstring& mechanism,
118 const std::wstring& criteria,
119 Json::Value* found_elements) {
120 LOG(TRACE) << "Entering ElementFinder::FindElements";
121
122 BrowserHandle browser;
123 int status_code = executor.GetCurrentBrowser(&browser);
124 if (status_code == WD_SUCCESS) {
125 if (mechanism == L"css") {
126 if (!this->HasNativeCssSelectorEngine(executor)) {
127 LOG(DEBUG) << "Element location strategy is CSS selectors, but "
128 << "document does not support CSS selectors. Falling back "
129 << "to using the Sizzle JavaScript CSS selector engine.";
130 status_code = this->FindElementsUsingSizzle(executor,
131 parent_wrapper,
132 criteria,
133 found_elements);
134 if (status_code != WD_SUCCESS) {
135 LOG(WARN) << "A JavaScript error was encountered finding elements using Sizzle.";
136 status_code = WD_SUCCESS;
137 *found_elements = Json::Value(Json::arrayValue);
138 }
139 return status_code;
140 }
141 }
142
143 LOG(DEBUG) << "Using FindElements atom to locate element having "
144 << LOGWSTRING(mechanism) << " = "
145 << LOGWSTRING(criteria);
146 CComPtr<IHTMLDocument2> doc;
147 browser->GetDocument(&doc);
148
149 std::wstring script_source(L"(function() { return (");
150 script_source += atoms::asString(atoms::FIND_ELEMENTS);
151 script_source += L")})();";
152
153 Script script_wrapper(doc, script_source, 3);
154 script_wrapper.AddArgument(mechanism);
155 script_wrapper.AddArgument(criteria);
156 if (parent_wrapper) {
157 script_wrapper.AddArgument(parent_wrapper->element());
158 }
159
160 status_code = script_wrapper.Execute();
161 if (status_code == WD_SUCCESS) {
162 Json::Value atom_result;
163 int converted_status_code = script_wrapper.ConvertResultToJsonValue(executor, &atom_result);
164 if (converted_status_code != WD_SUCCESS) {
165 LOG(WARN) << "Could not convert return from findElements atom to JSON value";
166 status_code = WD_SUCCESS;
167 *found_elements = Json::Value(Json::arrayValue);
168 } else {
169 int atom_status_code = atom_result["status"].asInt();
170 Json::Value atom_value = atom_result["value"];
171 status_code = atom_status_code;
172 *found_elements = atom_result["value"];

Callers 1

LocateElementsMethod · 0.45

Calls 11

asStringFunction · 0.85
GetCurrentBrowserMethod · 0.80
ValueClass · 0.70
LOGClass · 0.50
GetDocumentMethod · 0.45
AddArgumentMethod · 0.45
elementMethod · 0.45
ExecuteMethod · 0.45

Tested by

no test coverage detected