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

Method FindElementUsingSizzle

cpp/iedriver/ElementFinder.cpp:193–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193int ElementFinder::FindElementUsingSizzle(const IECommandExecutor& executor,
194 const ElementHandle parent_wrapper,
195 const std::wstring& criteria,
196 Json::Value* found_element) {
197 LOG(TRACE) << "Entering ElementFinder::FindElementUsingSizzle";
198
199 int result;
200
201 BrowserHandle browser;
202 result = executor.GetCurrentBrowser(&browser);
203 if (result != WD_SUCCESS) {
204 LOG(WARN) << "Unable to get browser";
205 return result;
206 }
207
208 std::wstring script_source(L"(function() { return function(){ if (!window.Sizzle) {");
209 script_source += atoms::asString(atoms::SIZZLE);
210 script_source += L"}\n";
211 script_source += L"var root = arguments[1] ? arguments[1] : document.documentElement;";
212 script_source += L"if (root['querySelector']) { return root.querySelector(arguments[0]); } ";
213 script_source += L"var results = []; Sizzle(arguments[0], root, results);";
214 script_source += L"return results.length > 0 ? results[0] : null;";
215 script_source += L"};})();";
216
217 CComPtr<IHTMLDocument2> doc;
218 browser->GetDocument(&doc);
219 Script script_wrapper(doc, script_source, 2);
220 script_wrapper.AddArgument(criteria);
221 if (parent_wrapper) {
222 CComPtr<IHTMLElement> parent(parent_wrapper->element());
223 script_wrapper.AddArgument(parent);
224 }
225 result = script_wrapper.Execute();
226
227 if (result == WD_SUCCESS) {
228 if (!script_wrapper.ResultIsElement()) {
229 LOG(WARN) << "Found result is not element";
230 result = ENOSUCHELEMENT;
231 } else {
232 result = script_wrapper.ConvertResultToJsonValue(executor,
233 found_element);
234 }
235 } else {
236 LOG(WARN) << "Unable to find elements";
237 result = ENOSUCHELEMENT;
238 }
239
240 return result;
241}
242
243int ElementFinder::FindElementsUsingSizzle(const IECommandExecutor& executor,
244 const ElementHandle parent_wrapper,

Callers 1

FindElementMethod · 0.95

Calls 9

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

Tested by

no test coverage detected