selenium-webdriver 4.51.0 → 4.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +15 -0
  3. data/Gemfile +14 -0
  4. data/README.md +20 -0
  5. data/bin/linux-arm64/selenium-manager +0 -0
  6. data/bin/linux-x86_64/selenium-manager +0 -0
  7. data/bin/macos/selenium-manager +0 -0
  8. data/bin/selenium-manager-THIRD-PARTY-NOTICES.txt +543 -226
  9. data/bin/selenium-manager.cdx.json +804 -722
  10. data/bin/windows/selenium-manager.exe +0 -0
  11. data/lib/selenium/webdriver/atoms/findElements.js +960 -250
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +153 -127
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +433 -364
  14. data/lib/selenium/webdriver/atoms.rb +4 -1
  15. data/lib/selenium/webdriver/bidi/protocol/bluetooth.rb +6 -6
  16. data/lib/selenium/webdriver/bidi/protocol/browser.rb +21 -9
  17. data/lib/selenium/webdriver/bidi/protocol/browsing_context.rb +109 -39
  18. data/lib/selenium/webdriver/bidi/protocol/emulation.rb +89 -44
  19. data/lib/selenium/webdriver/bidi/protocol/input.rb +95 -31
  20. data/lib/selenium/webdriver/bidi/protocol/log.rb +4 -4
  21. data/lib/selenium/webdriver/bidi/protocol/moz_debugging.rb +12 -10
  22. data/lib/selenium/webdriver/bidi/protocol/moz_profiler.rb +4 -4
  23. data/lib/selenium/webdriver/bidi/protocol/network.rb +82 -39
  24. data/lib/selenium/webdriver/bidi/protocol/script.rb +38 -24
  25. data/lib/selenium/webdriver/bidi/protocol/session.rb +61 -8
  26. data/lib/selenium/webdriver/bidi/protocol/storage.rb +3 -3
  27. data/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rb +3 -3
  28. data/lib/selenium/webdriver/bidi/protocol/web_extension.rb +17 -9
  29. data/lib/selenium/webdriver/bidi/serialization/record.rb +66 -24
  30. data/lib/selenium/webdriver/bidi/serialization.rb +2 -2
  31. data/lib/selenium/webdriver/bidi/support/bidi_generate.rb +228 -150
  32. data/lib/selenium/webdriver/common/client_config.rb +4 -1
  33. data/lib/selenium/webdriver/common/driver_finder.rb +5 -2
  34. data/lib/selenium/webdriver/common/websocket_connection.rb +51 -13
  35. data/lib/selenium/webdriver/remote/http/default.rb +17 -1
  36. data/lib/selenium/webdriver/version.rb +1 -1
  37. data/selenium-webdriver.gemspec +0 -12
  38. metadata +6 -163
@@ -1,287 +1,997 @@
1
1
  (function () {
2
- function findElements(target, root) {
3
- const INVALID_SELECTOR = 'invalid selector';
4
- const INVALID_ARGUMENT = 'invalid argument';
5
- const NO_SUCH_ELEMENT = 'no such element';
6
- function botError(code, message) {
7
- const err = new Error(message);
8
- err['code'] = code;
9
- return err;
10
- }
11
- function cssEscapeId(s) {
12
- return s.replace(/[\s'"\\#.:;,!?+<>=~*^$|%&@`{}\-/\[\]()]/g, (c) => '\\' + c);
13
- }
14
- function classNameMany(target, root) {
15
- if (!target) {
16
- throw botError(INVALID_SELECTOR, 'No class name specified');
17
- }
18
- target = target.trim();
19
- if (target.indexOf(' ') !== -1) {
20
- throw botError(INVALID_SELECTOR, 'Compound class names not permitted');
21
- }
22
- try {
23
- return Array.from(root.querySelectorAll('.' + target.replace(/\\/g, '\\\\').replace(/\./g, '\\.')));
24
- }
25
- catch (_e) {
26
- throw botError(INVALID_SELECTOR, 'An invalid or illegal class name was specified');
27
- }
2
+ var __seleniumAtom = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // javascript/atoms/typescript/find-elements.ts
22
+ var find_elements_exports = {};
23
+ __export(find_elements_exports, {
24
+ default: () => findElements
25
+ });
26
+
27
+ // javascript/atoms/typescript/core/error.ts
28
+ var INVALID_SELECTOR = "invalid selector";
29
+ var INVALID_ARGUMENT = "invalid argument";
30
+ var NO_SUCH_ELEMENT = "no such element";
31
+ function botError(code, message) {
32
+ const err = new Error(message);
33
+ err["code"] = code;
34
+ return err;
35
+ }
36
+
37
+ // javascript/atoms/typescript/core/attribute.ts
38
+ var SPLIT_STYLE_ATTRIBUTE_ON_SEMICOLONS = new RegExp(
39
+ `[;]+(?=(?:(?:[^"]*"){2})*[^"]*$)(?=(?:(?:[^']*'){2})*[^']*$)(?=(?:[^()]*\\([^()]*\\))*[^()]*$)`
40
+ );
41
+
42
+ // javascript/atoms/typescript/core/element.ts
43
+ var tagNameDescriptor = null;
44
+ function getTagNameDescriptor() {
45
+ if (tagNameDescriptor === null) {
46
+ tagNameDescriptor = Object.getOwnPropertyDescriptor(Element.prototype, "tagName");
47
+ }
48
+ return tagNameDescriptor;
49
+ }
50
+ function toUpperCaseTag(tagName) {
51
+ return tagName ? tagName.toUpperCase() : void 0;
52
+ }
53
+ function isElement(node, tagName) {
54
+ if (!node || node.nodeType !== 1) {
55
+ return false;
56
+ }
57
+ var asElement = node;
58
+ var descriptor = getTagNameDescriptor();
59
+ var rawTagName = descriptor && typeof descriptor.get === "function" ? descriptor.get.call(asElement) : asElement.tagName;
60
+ var upperTagName = typeof rawTagName === "string" ? rawTagName.toUpperCase() : "";
61
+ var normalizedTagName = toUpperCaseTag(tagName);
62
+ if (upperTagName === "FORM") {
63
+ return !normalizedTagName || normalizedTagName === "FORM";
64
+ }
65
+ return !!upperTagName && (!normalizedTagName || upperTagName === normalizedTagName);
66
+ }
67
+ function getParentElement(node) {
68
+ var current = node.parentNode;
69
+ while (current && current.nodeType !== Node.ELEMENT_NODE && current.nodeType !== Node.DOCUMENT_NODE && current.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
70
+ current = current.parentNode;
71
+ }
72
+ return current && current.nodeType === 1 ? current : null;
73
+ }
74
+ function getParentNodeInComposedDom(node) {
75
+ var parent = node.parentNode;
76
+ var slottable = node;
77
+ var parentWithShadow = parent;
78
+ if (parentWithShadow && parentWithShadow.shadowRoot && slottable.assignedSlot !== void 0) {
79
+ return slottable.assignedSlot ? slottable.assignedSlot.parentNode : null;
80
+ }
81
+ return parent;
82
+ }
83
+
84
+ // javascript/atoms/typescript/core/geometry.ts
85
+ function createRect(left, top, width, height) {
86
+ return {
87
+ left,
88
+ top,
89
+ right: left + width,
90
+ bottom: top + height,
91
+ width,
92
+ height
93
+ };
94
+ }
95
+ function clamp(value, min, max) {
96
+ return Math.min(Math.max(value, min), max);
97
+ }
98
+ function getAreaRelativeRect(area) {
99
+ var shape = area.shape.toLowerCase();
100
+ var coords = area.coords.split(",").map(function(value) {
101
+ return Number(value.trim());
102
+ });
103
+ if (shape === "rect" && coords.length === 4) {
104
+ return createRect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
28
105
  }
29
- function cssMany(target, root) {
30
- try {
31
- return Array.from(root.querySelectorAll(target));
106
+ if (shape === "circle" && coords.length === 3) {
107
+ return createRect(coords[0] - coords[2], coords[1] - coords[2], coords[2] * 2, coords[2] * 2);
108
+ }
109
+ if (shape === "poly" && coords.length > 2) {
110
+ var minX = coords[0];
111
+ var minY = coords[1];
112
+ var maxX = minX;
113
+ var maxY = minY;
114
+ for (var index = 2; index + 1 < coords.length; index += 2) {
115
+ minX = Math.min(minX, coords[index]);
116
+ maxX = Math.max(maxX, coords[index]);
117
+ minY = Math.min(minY, coords[index + 1]);
118
+ maxY = Math.max(maxY, coords[index + 1]);
119
+ }
120
+ return createRect(minX, minY, maxX - minX, maxY - minY);
121
+ }
122
+ return createRect(0, 0, 0, 0);
123
+ }
124
+ function findImageUsingMap(mapName, doc) {
125
+ return doc.querySelector('[usemap="#' + mapName.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"]');
126
+ }
127
+ function maybeFindImageMap(elem, getRect = getClientRect) {
128
+ var isMap = isElement(elem, "MAP");
129
+ if (!isMap && !isElement(elem, "AREA")) {
130
+ return null;
131
+ }
132
+ var map = isMap ? elem : isElement(elem.parentNode, "MAP") ? elem.parentNode : null;
133
+ var image = null;
134
+ var rect = createRect(0, 0, 0, 0);
135
+ if (isElement(map, "MAP") && map.name) {
136
+ image = findImageUsingMap(map.name, map.ownerDocument);
137
+ if (image) {
138
+ rect = getRect(image);
139
+ if (!isMap && isElement(elem, "AREA") && elem.shape.toLowerCase() !== "default") {
140
+ var relativeRect = getAreaRelativeRect(elem);
141
+ var relativeX = Math.min(Math.max(relativeRect.left, 0), rect.width);
142
+ var relativeY = Math.min(Math.max(relativeRect.top, 0), rect.height);
143
+ var width = Math.min(relativeRect.width, rect.width - relativeX);
144
+ var height = Math.min(relativeRect.height, rect.height - relativeY);
145
+ rect = createRect(relativeX + rect.left, relativeY + rect.top, width, height);
32
146
  }
33
- catch (_e) {
34
- throw botError(INVALID_SELECTOR, 'An invalid or illegal CSS selector was specified: ' + target);
147
+ }
148
+ }
149
+ return { image, rect };
150
+ }
151
+ function getClientRect(elem, getRect) {
152
+ var imageMap = maybeFindImageMap(elem, getRect || getClientRect);
153
+ if (imageMap) {
154
+ return imageMap.rect;
155
+ }
156
+ var elemTagName = typeof elem.tagName === "string" ? elem.tagName : "";
157
+ if (elemTagName.toUpperCase() === "HTML") {
158
+ var doc = elem.ownerDocument;
159
+ var sizeElem = doc.compatMode === "CSS1Compat" ? doc.documentElement : doc.body || doc.documentElement;
160
+ return createRect(0, 0, sizeElem.clientWidth, sizeElem.clientHeight);
161
+ }
162
+ try {
163
+ var nativeRect = elem.getBoundingClientRect();
164
+ return {
165
+ left: nativeRect.left,
166
+ top: nativeRect.top,
167
+ right: nativeRect.right,
168
+ bottom: nativeRect.bottom,
169
+ width: nativeRect.right - nativeRect.left,
170
+ height: nativeRect.bottom - nativeRect.top
171
+ };
172
+ } catch (_error) {
173
+ return createRect(0, 0, 0, 0);
174
+ }
175
+ }
176
+ function getClientRegion(elem, optRegion, getRect = getClientRect) {
177
+ var rect = getRect(elem);
178
+ if (!optRegion) {
179
+ return rect;
180
+ }
181
+ var region = "left" in optRegion ? optRegion : { left: optRegion.x, top: optRegion.y, width: 1, height: 1 };
182
+ var left = clamp(rect.left + region.left, rect.left, rect.right);
183
+ var top = clamp(rect.top + region.top, rect.top, rect.bottom);
184
+ var right = clamp(left + region.width, left, rect.right);
185
+ var bottom = clamp(top + region.height, top, rect.bottom);
186
+ return createRect(left, top, right - left, bottom - top);
187
+ }
188
+
189
+ // javascript/atoms/typescript/core/style.ts
190
+ function getEffectiveStyle(elem, propertyName) {
191
+ const win = elem.ownerDocument.defaultView;
192
+ const computed = win ? win.getComputedStyle(elem) : null;
193
+ if (!computed) {
194
+ return null;
195
+ }
196
+ return computed.getPropertyValue(propertyName) || null;
197
+ }
198
+
199
+ // javascript/atoms/typescript/core/overflow.ts
200
+ function getOverflowState(elem, optRegion, getStyle = getEffectiveStyle, getRect = getClientRect) {
201
+ var region = getClientRegion(elem, optRegion, getRect);
202
+ var ownerDoc = elem.ownerDocument;
203
+ var htmlElem = ownerDoc.documentElement;
204
+ var bodyElem = ownerDoc.body;
205
+ var htmlOverflowStyle = getStyle(htmlElem, "overflow") || "visible";
206
+ var treatAsFixedPosition = false;
207
+ function canBeOverflowed(container2, position) {
208
+ if (container2 === htmlElem) {
209
+ return true;
210
+ }
211
+ var display = getStyle(container2, "display") || "";
212
+ if (display.indexOf("inline") === 0 || display === "contents") {
213
+ return false;
214
+ }
215
+ if (position === "absolute" && getStyle(container2, "position") === "static") {
216
+ return false;
217
+ }
218
+ return true;
219
+ }
220
+ function getOverflowParent(current) {
221
+ var position = getStyle(current, "position");
222
+ if (position === "fixed") {
223
+ treatAsFixedPosition = true;
224
+ return current === htmlElem ? null : htmlElem;
225
+ }
226
+ var parent = getParentElement(current);
227
+ while (parent && !canBeOverflowed(parent, position)) {
228
+ parent = getParentElement(parent);
229
+ }
230
+ return parent;
231
+ }
232
+ function getOverflowStyles(current) {
233
+ var overflowElem = current;
234
+ if (htmlOverflowStyle === "visible") {
235
+ if (current === htmlElem && bodyElem) {
236
+ overflowElem = bodyElem;
237
+ } else if (current === bodyElem) {
238
+ return { x: "visible", y: "visible" };
35
239
  }
240
+ }
241
+ var overflow = {
242
+ x: getStyle(overflowElem, "overflow-x") || "visible",
243
+ y: getStyle(overflowElem, "overflow-y") || "visible"
244
+ };
245
+ if (current === htmlElem) {
246
+ overflow.x = overflow.x === "visible" ? "auto" : overflow.x;
247
+ overflow.y = overflow.y === "visible" ? "auto" : overflow.y;
248
+ }
249
+ return overflow;
36
250
  }
37
- function idMany(target, root) {
38
- if (!target) {
39
- return [];
251
+ function getScroll(current) {
252
+ if (current === htmlElem) {
253
+ return {
254
+ x: ownerDoc.defaultView ? ownerDoc.defaultView.pageXOffset : 0,
255
+ y: ownerDoc.defaultView ? ownerDoc.defaultView.pageYOffset : 0
256
+ };
257
+ }
258
+ return { x: current.scrollLeft, y: current.scrollTop };
259
+ }
260
+ function overflowStateOf(container2) {
261
+ return getOverflowState(container2, void 0, getStyle, getRect);
262
+ }
263
+ for (var container = getOverflowParent(elem); container; container = getOverflowParent(container)) {
264
+ var containerOverflow = getOverflowStyles(container);
265
+ if (containerOverflow.x === "visible" && containerOverflow.y === "visible") {
266
+ continue;
267
+ }
268
+ var containerRect = getRect(container);
269
+ if (containerRect.width === 0 || containerRect.height === 0) {
270
+ return "hidden";
271
+ }
272
+ var underflowsX = region.right < containerRect.left;
273
+ var underflowsY = region.bottom < containerRect.top;
274
+ if (underflowsX && containerOverflow.x === "hidden" || underflowsY && containerOverflow.y === "hidden") {
275
+ return "hidden";
276
+ }
277
+ if (underflowsX && containerOverflow.x !== "visible" || underflowsY && containerOverflow.y !== "visible") {
278
+ var containerScroll = getScroll(container);
279
+ var unscrollableX = region.right < containerRect.left - containerScroll.x;
280
+ var unscrollableY = region.bottom < containerRect.top - containerScroll.y;
281
+ if (unscrollableX && containerOverflow.x !== "visible" || unscrollableY && containerOverflow.y !== "visible") {
282
+ return "hidden";
40
283
  }
41
- if (!/^\d/.test(target)) {
42
- try {
43
- return Array.from(root.querySelectorAll('#' + cssEscapeId(target)));
44
- }
45
- catch (_e) {
46
- return [];
47
- }
284
+ return overflowStateOf(container) === "hidden" ? "hidden" : "scroll";
285
+ }
286
+ var overflowsX = region.left >= containerRect.left + containerRect.width;
287
+ var overflowsY = region.top >= containerRect.top + containerRect.height;
288
+ if (overflowsX && containerOverflow.x === "hidden" || overflowsY && containerOverflow.y === "hidden") {
289
+ return "hidden";
290
+ }
291
+ if (overflowsX && containerOverflow.x !== "visible" || overflowsY && containerOverflow.y !== "visible") {
292
+ if (treatAsFixedPosition) {
293
+ var docScroll = getScroll(container);
294
+ if (region.left >= htmlElem.scrollWidth - docScroll.x || region.right >= htmlElem.scrollHeight - docScroll.y) {
295
+ return "hidden";
296
+ }
48
297
  }
49
- return Array.from(root.querySelectorAll('*')).filter(el => el.getAttribute('id') === target);
298
+ return overflowStateOf(container) === "hidden" ? "hidden" : "scroll";
299
+ }
300
+ }
301
+ return "none";
302
+ }
303
+
304
+ // javascript/atoms/typescript/core/shown.ts
305
+ function isShownElement(elem, optIgnoreOpacity) {
306
+ var computedStyleCache = /* @__PURE__ */ new Map();
307
+ var clientRectCache = /* @__PURE__ */ new Map();
308
+ var displayedCache = /* @__PURE__ */ new Map();
309
+ function getEffectiveStyle2(elem2, propertyName) {
310
+ var computed = computedStyleCache.get(elem2);
311
+ if (computed === void 0) {
312
+ var win = elem2.ownerDocument.defaultView;
313
+ computed = win ? win.getComputedStyle(elem2) || null : null;
314
+ computedStyleCache.set(elem2, computed);
315
+ }
316
+ if (!computed) {
317
+ return null;
318
+ }
319
+ var value = computed.getPropertyValue(propertyName);
320
+ return value || null;
321
+ }
322
+ function getOpacity(elem2) {
323
+ var opacityStyle = getEffectiveStyle2(elem2, "opacity");
324
+ var opacity = opacityStyle ? Number(opacityStyle) : 1;
325
+ var parent = getParentElement(elem2);
326
+ return parent ? opacity * getOpacity(parent) : opacity;
50
327
  }
51
- function getLinkText(el) {
52
- const text = el.innerText !== undefined ? el.innerText : el.textContent || '';
53
- return text.replace(/^[\s]+|[\s]+$/g, '');
328
+ function getClientRect3(elem2) {
329
+ var cachedRect = clientRectCache.get(elem2);
330
+ if (cachedRect) {
331
+ return cachedRect;
332
+ }
333
+ var rect = getClientRect(elem2, getClientRect3);
334
+ clientRectCache.set(elem2, rect);
335
+ return rect;
54
336
  }
55
- function linkTextMany(target, root, partial) {
56
- return Array.from(root.querySelectorAll('a')).filter(el => {
57
- const text = getLinkText(el);
58
- return partial ? text.indexOf(target) !== -1 : text === target;
59
- });
337
+ function maybeFindImageMap2(elem2) {
338
+ return maybeFindImageMap(elem2, getClientRect3);
60
339
  }
61
- function nameMany(target, root) {
62
- return Array.from(root.querySelectorAll('[name="' + target.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"]'));
340
+ function getClientRegion2(elem2) {
341
+ return getClientRegion(elem2, void 0, getClientRect3);
63
342
  }
64
- function tagNameMany(target, root) {
65
- if (target === '') {
66
- throw botError(INVALID_SELECTOR, 'Unable to locate an element with the tagName ""');
343
+ function getOverflowState2(elem2) {
344
+ return getOverflowState(elem2, void 0, getEffectiveStyle2, getClientRect3);
345
+ }
346
+ function isShownInternal(elem2, ignoreOpacity, displayedFn) {
347
+ if (!isElement(elem2)) {
348
+ throw new Error("Argument to isShown must be of type Element");
349
+ }
350
+ if (isElement(elem2, "BODY")) {
351
+ return true;
352
+ }
353
+ if (isElement(elem2, "OPTION") || isElement(elem2, "OPTGROUP")) {
354
+ var select = elem2.closest("select");
355
+ return !!select && isShownInternal(select, true, displayedFn);
356
+ }
357
+ var imageMap = maybeFindImageMap2(elem2);
358
+ if (imageMap) {
359
+ return !!imageMap.image && imageMap.rect.width > 0 && imageMap.rect.height > 0 && isShownInternal(imageMap.image, ignoreOpacity, displayedFn);
360
+ }
361
+ if (isElement(elem2, "INPUT") && elem2.type.toLowerCase() === "hidden") {
362
+ return false;
363
+ }
364
+ if (isElement(elem2, "NOSCRIPT")) {
365
+ return false;
366
+ }
367
+ var visibility = getEffectiveStyle2(elem2, "visibility");
368
+ if (visibility === "collapse" || visibility === "hidden") {
369
+ return false;
370
+ }
371
+ if (!displayedFn(elem2)) {
372
+ return false;
373
+ }
374
+ if (!ignoreOpacity && getOpacity(elem2) === 0) {
375
+ return false;
376
+ }
377
+ function positiveSize(element) {
378
+ var rect = getClientRect3(element);
379
+ if (rect.height > 0 && rect.width > 0) {
380
+ return true;
67
381
  }
68
- if ('getElementsByTagName' in root) {
69
- return Array.from(root.getElementsByTagName(target));
382
+ if (isElement(element, "PATH") && (rect.height > 0 || rect.width > 0)) {
383
+ var strokeWidth = getEffectiveStyle2(element, "stroke-width");
384
+ return !!strokeWidth && parseInt(strokeWidth, 10) > 0;
70
385
  }
71
- const elements = Array.from(root.querySelectorAll('*'));
72
- if (target === '*') {
73
- return elements;
386
+ var elementVisibility = getEffectiveStyle2(element, "visibility");
387
+ if (elementVisibility === "collapse" || elementVisibility === "hidden") {
388
+ return false;
74
389
  }
75
- const html = 'http://www.w3.org/1999/xhtml';
76
- const folded = target.toLowerCase();
77
- return elements.filter(el => el.namespaceURI === html ? el.localName === folded : el.localName === target);
78
- }
79
- const DEFAULT_NS_RESOLVER = (function () {
80
- const ns = { svg: 'http://www.w3.org/2000/svg' };
81
- return (prefix) => ns[prefix] || null;
82
- })();
83
- const ORDERED_NODE_SNAPSHOT_TYPE = 7;
84
- function xpathMany(target, root) {
85
- const doc = root.documentElement ? root : root.ownerDocument;
86
- if (!doc.documentElement) {
87
- return [];
390
+ if (!displayedFn(element)) {
391
+ return false;
88
392
  }
89
- try {
90
- let resolver = null;
91
- if (target.indexOf(':') !== -1) {
92
- const reversedNs = {};
93
- const allNodes = doc.getElementsByTagName('*');
94
- for (let i = 0; i < allNodes.length; i++) {
95
- const n = allNodes[i];
96
- const ns = n.namespaceURI;
97
- if (ns && !reversedNs[ns]) {
98
- let prefix = n.lookupPrefix(ns);
99
- if (!prefix) {
100
- const m = ns.match('.*/(\\w+)/?$');
101
- prefix = m ? m[1] : 'xhtml';
102
- }
103
- reversedNs[ns] = prefix;
104
- }
105
- }
106
- const namespaces = {};
107
- for (const key in reversedNs) {
108
- namespaces[reversedNs[key]] = key;
109
- }
110
- resolver = (prefix) => namespaces[prefix || ''] || null;
111
- }
112
- let result = null;
113
- try {
114
- result = doc.evaluate(target, root, resolver, ORDERED_NODE_SNAPSHOT_TYPE, null);
115
- }
116
- catch (te) {
117
- if (te.name === 'TypeError') {
118
- const fallback = doc.createNSResolver ? doc.createNSResolver(doc.documentElement) : DEFAULT_NS_RESOLVER;
119
- result = doc.evaluate(target, root, fallback, ORDERED_NODE_SNAPSHOT_TYPE, null);
120
- }
121
- else {
122
- throw te;
123
- }
124
- }
125
- if (!result) {
126
- return [];
127
- }
128
- const results = [];
129
- for (let i = 0; i < result.snapshotLength; i++) {
130
- const node = result.snapshotItem(i);
131
- if (!node || node.nodeType !== Node.ELEMENT_NODE) {
132
- throw botError(INVALID_SELECTOR, 'The result of the xpath expression "' + target + '" is: ' + node + '. It should be an element.');
133
- }
134
- results.push(node);
135
- }
136
- return results;
393
+ if (getEffectiveStyle2(element, "overflow") === "hidden") {
394
+ return false;
137
395
  }
138
- catch (ex) {
139
- if (ex.name === 'NS_ERROR_ILLEGAL_VALUE') {
140
- return [];
141
- }
142
- if (ex.code === INVALID_SELECTOR) {
143
- throw ex;
396
+ for (var index = 0; index < element.childNodes.length; index += 1) {
397
+ var child = element.childNodes[index];
398
+ if (child.nodeType === Node.TEXT_NODE) {
399
+ var text = child.nodeValue || "";
400
+ if (/^[\s]*$/.test(text) && /[\n\r\t]/.test(text)) {
401
+ continue;
144
402
  }
145
- throw botError(INVALID_SELECTOR, 'Unable to locate an element with the xpath expression ' + target + ' because of the following error:\n' + ex);
403
+ return true;
404
+ }
405
+ if (isElement(child) && positiveSize(child)) {
406
+ return true;
407
+ }
408
+ }
409
+ return false;
410
+ }
411
+ if (!positiveSize(elem2)) {
412
+ return false;
413
+ }
414
+ function hiddenByOverflow(element) {
415
+ if (getOverflowState2(element) !== "hidden") {
416
+ return false;
417
+ }
418
+ for (var index = 0; index < element.childNodes.length; index += 1) {
419
+ var child = element.childNodes[index];
420
+ if (isElement(child) && !hiddenByOverflow(child) && positiveSize(child)) {
421
+ return false;
422
+ }
423
+ }
424
+ return true;
425
+ }
426
+ return !hiddenByOverflow(elem2);
427
+ }
428
+ function displayed(node) {
429
+ var cached = displayedCache.get(node);
430
+ if (cached !== void 0) {
431
+ return cached;
432
+ }
433
+ if (isElement(node)) {
434
+ var display = getEffectiveStyle2(node, "display");
435
+ var contentVisibility = getEffectiveStyle2(node, "content-visibility");
436
+ if (display === "none" || contentVisibility === "hidden") {
437
+ displayedCache.set(node, false);
438
+ return false;
146
439
  }
440
+ }
441
+ var parent = getParentNodeInComposedDom(node);
442
+ if (typeof ShadowRoot === "function" && parent instanceof ShadowRoot) {
443
+ if (parent.host.shadowRoot && parent.host.shadowRoot !== parent) {
444
+ displayedCache.set(node, false);
445
+ return false;
446
+ }
447
+ parent = parent.host;
448
+ }
449
+ if (parent && (parent.nodeType === Node.DOCUMENT_NODE || parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE)) {
450
+ displayedCache.set(node, true);
451
+ return true;
452
+ }
453
+ if (isElement(parent, "DETAILS") && !parent.open && !isElement(node, "SUMMARY")) {
454
+ displayedCache.set(node, false);
455
+ return false;
456
+ }
457
+ var result = !!parent && displayed(parent);
458
+ displayedCache.set(node, result);
459
+ return result;
460
+ }
461
+ return isShownInternal(elem, !!optIgnoreOpacity, displayed);
462
+ }
463
+ var shown_default = isShownElement;
464
+
465
+ // javascript/atoms/typescript/get-text.ts
466
+ var INLINE_DISPLAY_BOXES = [
467
+ "inline",
468
+ "inline-block",
469
+ "inline-table",
470
+ "none",
471
+ "table-cell",
472
+ "table-column",
473
+ "table-column-group"
474
+ ];
475
+ var CAPITALIZE_PATTERNS = function() {
476
+ var letter = "\\p{L}\\u24B6-\\u24E9";
477
+ var wordCharacter = "'_\\p{M}\\p{N}" + letter;
478
+ try {
479
+ return [
480
+ new RegExp("(^|[^" + wordCharacter + "])([" + letter + "])", "gu"),
481
+ new RegExp(
482
+ "(^|[^" + wordCharacter + "])([_*])([" + letter + "])",
483
+ "gu"
484
+ )
485
+ ];
486
+ } catch (_ignored) {
487
+ var latinLetters = "A-Za-z\\u00C0-\\u02AF\\u1E00-\\u1EFF\\u24B6-\\u24E9";
488
+ var wordChars = "'_0-9" + latinLetters + "\\u0300-\\u036F\\u1AB0-\\u1AFF\\u1DC0-\\u1DFF";
489
+ var lowerLetters = "A-Za-z\\u00C0-\\u02AF\\u1E00-\\u1EFF\\u24D0-\\u24E9";
490
+ return [
491
+ new RegExp("(^|[^" + wordChars + "])([" + latinLetters + "])", "g"),
492
+ new RegExp("(^|[^" + wordChars + "])([_*])([" + lowerLetters + "])", "g")
493
+ ];
494
+ }
495
+ }();
496
+ var BREAKING_SPACE_RE = new RegExp("[ \\f\\t\\v\\u2028\\u2029]+", "g");
497
+ var PRE_SPACE_RE = new RegExp("[ \\f\\t\\v\\u2028\\u2029]", "g");
498
+ function trimExcludingNbsp(str) {
499
+ return str.replace(/^[^\S\xa0]+|[^\S\xa0]+$/g, "");
500
+ }
501
+ function isEmptyOrWhitespace(str) {
502
+ return /^[\s\xa0]*$/.test(str);
503
+ }
504
+ function concatenateCleanedLines(lines) {
505
+ const trimmedLines = lines.map(trimExcludingNbsp);
506
+ const joined = trimmedLines.join("\n");
507
+ const trimmed = trimExcludingNbsp(joined);
508
+ return trimmed.replace(/\xa0/g, " ");
509
+ }
510
+ function appendTextFromTextNode(textNode, lines, whitespace, textTransform) {
511
+ var text = (textNode.nodeValue || "").replace(/[\u200b\u200e\u200f]/g, "");
512
+ text = text.replace(/(\r\n|\r|\n)/g, "\n");
513
+ if (whitespace === "normal" || whitespace === "nowrap") {
514
+ text = text.replace(/\n/g, " ");
515
+ }
516
+ if (whitespace === "pre" || whitespace === "pre-wrap") {
517
+ text = text.replace(PRE_SPACE_RE, "\xA0");
518
+ } else {
519
+ text = text.replace(BREAKING_SPACE_RE, " ");
520
+ }
521
+ if (textTransform === "capitalize") {
522
+ text = text.replace(CAPITALIZE_PATTERNS[0], function() {
523
+ return arguments[1] + arguments[2].toUpperCase();
524
+ });
525
+ text = text.replace(CAPITALIZE_PATTERNS[1], function() {
526
+ return arguments[1] + arguments[2] + arguments[3].toUpperCase();
527
+ });
528
+ } else if (textTransform === "uppercase") {
529
+ text = text.toUpperCase();
530
+ } else if (textTransform === "lowercase") {
531
+ text = text.toLowerCase();
147
532
  }
148
- function getClientRect(element) {
149
- const r = element.getBoundingClientRect();
150
- return { left: r.left, top: r.top, width: r.width, height: r.height };
533
+ var currLine = lines.pop() || "";
534
+ if (currLine.endsWith(" ") && text.startsWith(" ")) {
535
+ text = text.substring(1);
151
536
  }
152
- function resolveAnchor(selector) {
153
- if (selector instanceof Element) {
154
- return selector;
537
+ lines.push(currLine + text);
538
+ }
539
+ function appendTextFromElementCommon(elem, lines, isShownFn, childNodeFn) {
540
+ function currLine() {
541
+ var _a;
542
+ return (_a = lines[lines.length - 1]) != null ? _a : "";
543
+ }
544
+ const node = elem;
545
+ if (isElement(node, "BR")) {
546
+ lines.push("");
547
+ return;
548
+ }
549
+ const isTD = isElement(elem, "TD");
550
+ const display = getEffectiveStyle(elem, "display");
551
+ const isBlock = !isTD && !INLINE_DISPLAY_BOXES.includes(display || "");
552
+ const previousElementSibling = elem.previousElementSibling;
553
+ const prevDisplay = previousElementSibling ? getEffectiveStyle(previousElementSibling, "display") : "";
554
+ const thisFloat = getEffectiveStyle(elem, "float");
555
+ const runIntoThis = prevDisplay === "run-in" && thisFloat === "none";
556
+ if (isBlock && !runIntoThis && !isEmptyOrWhitespace(currLine())) {
557
+ lines.push("");
558
+ }
559
+ const shown = isShownFn(elem);
560
+ var whitespace = null;
561
+ var textTransform = null;
562
+ if (shown) {
563
+ whitespace = getEffectiveStyle(elem, "white-space");
564
+ textTransform = getEffectiveStyle(elem, "text-transform");
565
+ }
566
+ for (var i = 0; i < elem.childNodes.length; i++) {
567
+ childNodeFn(elem.childNodes[i], lines, shown, whitespace, textTransform);
568
+ }
569
+ const line = currLine();
570
+ if ((isTD || display === "table-cell") && line && !line.endsWith(" ")) {
571
+ lines[lines.length - 1] += " ";
572
+ }
573
+ if (isBlock && display !== "run-in" && !isEmptyOrWhitespace(line)) {
574
+ lines.push("");
575
+ }
576
+ }
577
+ function appendTextFromElement(elem, lines) {
578
+ appendTextFromElementCommon(
579
+ elem,
580
+ lines,
581
+ shown_default,
582
+ function(node, lines2, shown, whitespace, textTransform) {
583
+ if (node.nodeType === Node.TEXT_NODE && shown) {
584
+ appendTextFromTextNode(
585
+ node,
586
+ lines2,
587
+ whitespace,
588
+ textTransform
589
+ );
590
+ } else if (isElement(node)) {
591
+ appendTextFromElement(node, lines2);
155
592
  }
156
- if (typeof selector === 'function') {
157
- return resolveAnchor(selector());
593
+ }
594
+ );
595
+ }
596
+ function isNodeDistributedIntoShadowDom(node) {
597
+ if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.TEXT_NODE) {
598
+ var slottable = node;
599
+ return slottable.assignedSlot != null;
600
+ }
601
+ return false;
602
+ }
603
+ function appendTextFromNodeInComposedDom(node, lines, shown, whitespace, textTransform) {
604
+ if (node.nodeType === Node.TEXT_NODE && shown) {
605
+ appendTextFromTextNode(node, lines, whitespace, textTransform);
606
+ } else if (isElement(node)) {
607
+ const castElem = node;
608
+ if (isElement(node, "SLOT")) {
609
+ var parentNode = node;
610
+ while (parentNode.parentNode) {
611
+ parentNode = parentNode.parentNode;
158
612
  }
159
- if (selector && typeof selector === 'object') {
160
- let found = root ? findElements(selector, root) : [];
161
- if (!found.length) {
162
- found = findElements(selector);
163
- }
164
- if (!found.length) {
165
- throw botError(NO_SUCH_ELEMENT, 'No element has been found by ' + JSON.stringify(selector));
166
- }
167
- return found[0];
613
+ if (typeof ShadowRoot === "function" && parentNode instanceof ShadowRoot) {
614
+ const slot = node;
615
+ const assigned = slot.assignedNodes();
616
+ const childrenToTraverse = assigned.length > 0 ? assigned : slot.childNodes;
617
+ for (var i = 0; i < childrenToTraverse.length; i++) {
618
+ appendTextFromNodeInComposedDom(
619
+ childrenToTraverse[i],
620
+ lines,
621
+ shown,
622
+ whitespace,
623
+ textTransform
624
+ );
625
+ }
626
+ } else {
627
+ appendTextFromElementInComposedDom(castElem, lines);
168
628
  }
169
- throw botError(INVALID_ARGUMENT, 'Selector is of wrong type: ' + JSON.stringify(selector));
629
+ } else {
630
+ appendTextFromElementInComposedDom(castElem, lines);
631
+ }
170
632
  }
171
- function makeProximityFilter(selector, test) {
172
- return (candidate) => test(getClientRect(resolveAnchor(selector)), getClientRect(candidate));
633
+ }
634
+ function appendTextFromElementInComposedDom(elem, lines) {
635
+ if (elem.shadowRoot) {
636
+ const whitespace = getEffectiveStyle(elem, "white-space");
637
+ const textTransform = getEffectiveStyle(elem, "text-transform");
638
+ elem.shadowRoot.childNodes.forEach((node) => appendTextFromNodeInComposedDom(node, lines, true, whitespace, textTransform));
173
639
  }
174
- const RELATIVE_STRATEGIES = {
175
- above: (sel) => makeProximityFilter(sel, (a, c) => c.top + c.height <= a.top),
176
- below: (sel) => makeProximityFilter(sel, (a, c) => c.top >= a.top + a.height),
177
- left: (sel) => makeProximityFilter(sel, (a, c) => c.left + c.width <= a.left),
178
- right: (sel) => makeProximityFilter(sel, (a, c) => c.left >= a.left + a.width),
179
- near: (sel, distArg) => {
180
- const distFromSelector = typeof sel['distance'] === 'number'
181
- ? sel['distance']
182
- : 0;
183
- const distance = typeof distArg === 'number' && distArg > 0 ? distArg : distFromSelector || 50;
184
- return (candidate) => {
185
- const anchor = resolveAnchor(sel);
186
- if (anchor === candidate)
187
- return false;
188
- const a = getClientRect(anchor);
189
- const c = getClientRect(candidate);
190
- const expanded = { left: a.left - distance, top: a.top - distance, width: a.width + distance * 2, height: a.height + distance * 2 };
191
- return (c.left < expanded.left + expanded.width &&
192
- c.left + c.width > expanded.left &&
193
- c.top < expanded.top + expanded.height &&
194
- c.top + c.height > expanded.top);
195
- };
196
- },
197
- straightAbove: (sel) => makeProximityFilter(sel, (a, c) => c.left < a.left + a.width && c.left + c.width > a.left && c.top + c.height <= a.top),
198
- straightBelow: (sel) => makeProximityFilter(sel, (a, c) => c.left < a.left + a.width && c.left + c.width > a.left && c.top >= a.top + a.height),
199
- straightLeft: (sel) => makeProximityFilter(sel, (a, c) => c.top < a.top + a.height && c.top + c.height > a.top && c.left + c.width <= a.left),
200
- straightRight: (sel) => makeProximityFilter(sel, (a, c) => c.top < a.top + a.height && c.top + c.height > a.top && c.left >= a.left + a.width),
201
- };
202
- function sortByProximity(anchor, elements) {
203
- const ar = getClientRect(anchor);
204
- const acx = ar.left + Math.max(1, ar.width) / 2;
205
- const acy = ar.top + Math.max(1, ar.height) / 2;
206
- return elements.slice().sort((a, b) => {
207
- const ra = getClientRect(a);
208
- const rb = getClientRect(b);
209
- const da = Math.sqrt(Math.pow(acx - (ra.left + Math.max(1, ra.width) / 2), 2) + Math.pow(acy - (ra.top + Math.max(1, ra.height) / 2), 2));
210
- const db = Math.sqrt(Math.pow(acx - (rb.left + Math.max(1, rb.width) / 2), 2) + Math.pow(acy - (rb.top + Math.max(1, rb.height) / 2), 2));
211
- return da - db;
212
- });
213
- }
214
- function relativeMany(target, root) {
215
- if (!Object.prototype.hasOwnProperty.call(target, 'root') || !Object.prototype.hasOwnProperty.call(target, 'filters')) {
216
- throw botError(INVALID_ARGUMENT, 'Locator not suitable for relative locators: ' + JSON.stringify(target));
217
- }
218
- const filters = target['filters'];
219
- if (!Array.isArray(filters)) {
220
- throw botError(INVALID_ARGUMENT, 'Targets should be an array: ' + JSON.stringify(target));
640
+ appendTextFromElementCommon(
641
+ elem,
642
+ lines,
643
+ shown_default,
644
+ function(node, lines2, shown, whitespace, textTransform) {
645
+ if (!isNodeDistributedIntoShadowDom(node)) {
646
+ appendTextFromNodeInComposedDom(node, lines2, shown, whitespace, textTransform);
221
647
  }
222
- let elements;
223
- const rootTarget = target['root'];
224
- if (rootTarget instanceof Element) {
225
- elements = [rootTarget];
648
+ }
649
+ );
650
+ }
651
+ function getText(element) {
652
+ const lines = [];
653
+ if (typeof ShadowRoot === "function") {
654
+ appendTextFromElementInComposedDom(element, lines);
655
+ } else {
656
+ appendTextFromElement(element, lines);
657
+ }
658
+ return concatenateCleanedLines(lines);
659
+ }
660
+ var get_text_default = getText;
661
+
662
+ // javascript/atoms/typescript/core/locators.ts
663
+ function cssEscapeId(s) {
664
+ return s.replace(/[\s'"\\#.:;,!?+<>=~*^$|%&@`{}\-/\[\]()]/g, (c) => "\\" + c);
665
+ }
666
+ function hasCssEscape() {
667
+ return typeof CSS !== "undefined" && typeof CSS.escape === "function";
668
+ }
669
+ function idSelector(target) {
670
+ if (target.indexOf("\0") !== -1) {
671
+ return null;
672
+ }
673
+ if (hasCssEscape()) {
674
+ return "#" + CSS.escape(target);
675
+ }
676
+ return /^\d/.test(target) ? null : "#" + cssEscapeId(target);
677
+ }
678
+ function classSelector(target) {
679
+ return "." + (hasCssEscape() ? CSS.escape(target) : cssEscapeId(target));
680
+ }
681
+ function nameSelector(target) {
682
+ if (target.indexOf("\0") !== -1) {
683
+ return null;
684
+ }
685
+ if (hasCssEscape()) {
686
+ return '[name="' + CSS.escape(target) + '"]';
687
+ }
688
+ if (/[\r\n\f]/.test(target)) {
689
+ return null;
690
+ }
691
+ return '[name="' + target.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"]';
692
+ }
693
+ function attributeMany(selector, attr, target, root) {
694
+ if (selector !== null) {
695
+ try {
696
+ return Array.from(root.querySelectorAll(selector));
697
+ } catch (_e) {
698
+ }
699
+ }
700
+ return Array.from(root.querySelectorAll("*")).filter((el) => el.getAttribute(attr) === target);
701
+ }
702
+ function normalizeLinkText(s) {
703
+ return s.replace(/\u00a0/g, " ");
704
+ }
705
+ function getLinkText(el) {
706
+ return get_text_default(el).replace(/^[\s]+|[\s]+$/g, "");
707
+ }
708
+ function classNameMany(target, root) {
709
+ if (!target) {
710
+ throw botError(INVALID_SELECTOR, "No class name specified");
711
+ }
712
+ target = target.trim();
713
+ if (target.indexOf(" ") !== -1) {
714
+ throw botError(INVALID_SELECTOR, "Compound class names not permitted");
715
+ }
716
+ try {
717
+ return Array.from(root.querySelectorAll(classSelector(target)));
718
+ } catch (_e) {
719
+ throw botError(INVALID_SELECTOR, "An invalid or illegal class name was specified");
720
+ }
721
+ }
722
+ function cssMany(target, root) {
723
+ try {
724
+ return Array.from(root.querySelectorAll(target));
725
+ } catch (_e) {
726
+ throw botError(INVALID_SELECTOR, "An invalid or illegal CSS selector was specified: " + target);
727
+ }
728
+ }
729
+ function idMany(target, root) {
730
+ if (!target) {
731
+ return [];
732
+ }
733
+ return attributeMany(idSelector(target), "id", target, root);
734
+ }
735
+ function linkTextMany(target, root, partial) {
736
+ target = normalizeLinkText(target);
737
+ return Array.from(root.querySelectorAll("a")).filter((el) => {
738
+ const text = getLinkText(el);
739
+ return partial ? text.indexOf(target) !== -1 : text === target;
740
+ });
741
+ }
742
+ function nameMany(target, root) {
743
+ return attributeMany(nameSelector(target), "name", target, root);
744
+ }
745
+ function tagNameMany(target, root) {
746
+ if (target === "") {
747
+ throw botError(INVALID_SELECTOR, 'Unable to locate an element with the tagName ""');
748
+ }
749
+ if ("getElementsByTagName" in root) {
750
+ return Array.from(root.getElementsByTagName(target));
751
+ }
752
+ const elements = Array.from(root.querySelectorAll("*"));
753
+ if (target === "*") {
754
+ return elements;
755
+ }
756
+ const html = "http://www.w3.org/1999/xhtml";
757
+ const folded = target.toLowerCase();
758
+ return elements.filter((el) => el.namespaceURI === html ? el.localName === folded : el.localName === target);
759
+ }
760
+ var DEFAULT_NS_RESOLVER = /* @__PURE__ */ function() {
761
+ const ns = { svg: "http://www.w3.org/2000/svg" };
762
+ return (prefix) => ns[prefix] || null;
763
+ }();
764
+ var ORDERED_NODE_SNAPSHOT_TYPE = 7;
765
+ function buildNsResolver(target, doc) {
766
+ if (target.indexOf(":") === -1) {
767
+ return null;
768
+ }
769
+ const reversedNs = {};
770
+ const allNodes = doc.getElementsByTagName("*");
771
+ for (let i = 0; i < allNodes.length; i++) {
772
+ const n = allNodes[i];
773
+ const ns = n.namespaceURI;
774
+ if (ns && !reversedNs[ns]) {
775
+ let prefix = n.lookupPrefix(ns);
776
+ if (!prefix) {
777
+ const m = ns.match(".*/(\\w+)/?$");
778
+ prefix = m ? m[1] : "xhtml";
226
779
  }
227
- else {
228
- elements = findElements(rootTarget, root);
780
+ reversedNs[ns] = prefix;
781
+ }
782
+ }
783
+ const namespaces = {};
784
+ for (const key in reversedNs) {
785
+ namespaces[reversedNs[key]] = key;
786
+ }
787
+ return (prefix) => namespaces[prefix || ""] || null;
788
+ }
789
+ function xpathMany(target, root) {
790
+ const doc = root.documentElement ? root : root.ownerDocument;
791
+ if (!doc.documentElement) {
792
+ return [];
793
+ }
794
+ try {
795
+ const resolver = buildNsResolver(target, doc);
796
+ let result = null;
797
+ try {
798
+ result = doc.evaluate(target, root, resolver, ORDERED_NODE_SNAPSHOT_TYPE, null);
799
+ } catch (te) {
800
+ if (te.name === "TypeError") {
801
+ const fallback = doc.createNSResolver ? doc.createNSResolver(doc.documentElement) : DEFAULT_NS_RESOLVER;
802
+ result = doc.evaluate(target, root, fallback, ORDERED_NODE_SNAPSHOT_TYPE, null);
803
+ } else {
804
+ throw te;
229
805
  }
230
- if (!elements.length) {
231
- return [];
806
+ }
807
+ if (!result) {
808
+ return [];
809
+ }
810
+ const results = [];
811
+ for (let i = 0; i < result.snapshotLength; i++) {
812
+ const node = result.snapshotItem(i);
813
+ if (!node || node.nodeType !== Node.ELEMENT_NODE) {
814
+ throw botError(
815
+ INVALID_SELECTOR,
816
+ 'The result of the xpath expression "' + target + '" is: ' + node + ". It should be an element."
817
+ );
232
818
  }
233
- const matched = elements.filter(el => {
234
- if (!el)
235
- return false;
236
- return filters.every(filter => {
237
- const strategy = RELATIVE_STRATEGIES[filter.kind];
238
- if (!strategy) {
239
- throw botError(INVALID_ARGUMENT, 'Cannot find filter suitable for ' + filter.kind);
240
- }
241
- return strategy(...filter.args)(el);
242
- });
243
- });
244
- const finalFilter = filters[filters.length - 1];
245
- if (!finalFilter || !RELATIVE_STRATEGIES[finalFilter.kind]) {
246
- return matched;
819
+ results.push(node);
820
+ }
821
+ return results;
822
+ } catch (ex) {
823
+ if (ex.name === "NS_ERROR_ILLEGAL_VALUE") {
824
+ return [];
825
+ }
826
+ if (ex.code === INVALID_SELECTOR) {
827
+ throw ex;
828
+ }
829
+ throw botError(
830
+ INVALID_SELECTOR,
831
+ "Unable to locate an element with the xpath expression " + target + " because of the following error:\n" + ex
832
+ );
833
+ }
834
+ }
835
+ function getClientRect2(element) {
836
+ const r = element.getBoundingClientRect();
837
+ return { left: r.left, top: r.top, width: r.width, height: r.height };
838
+ }
839
+ function resolveAnchor(selector, outerRoot) {
840
+ if (selector instanceof Element) {
841
+ return selector;
842
+ }
843
+ if (typeof selector === "function") {
844
+ return resolveAnchor(selector(), outerRoot);
845
+ }
846
+ if (selector && typeof selector === "object") {
847
+ let found = outerRoot ? findElements(selector, outerRoot) : [];
848
+ if (!found.length) {
849
+ found = findElements(selector);
850
+ }
851
+ if (!found.length) {
852
+ throw botError(NO_SUCH_ELEMENT, "No element has been found by " + JSON.stringify(selector));
853
+ }
854
+ return found[0];
855
+ }
856
+ throw botError(INVALID_ARGUMENT, "Selector is of wrong type: " + JSON.stringify(selector));
857
+ }
858
+ function makeProximityFilter(selector, outerRoot, test) {
859
+ return (candidate) => test(getClientRect2(resolveAnchor(selector, outerRoot)), getClientRect2(candidate));
860
+ }
861
+ function sortByProximity(anchor, elements) {
862
+ const ar = getClientRect2(anchor);
863
+ const acx = ar.left + Math.max(1, ar.width) / 2;
864
+ const acy = ar.top + Math.max(1, ar.height) / 2;
865
+ return elements.slice().sort((a, b) => {
866
+ const ra = getClientRect2(a);
867
+ const rb = getClientRect2(b);
868
+ const da = Math.sqrt(
869
+ Math.pow(acx - (ra.left + Math.max(1, ra.width) / 2), 2) + Math.pow(acy - (ra.top + Math.max(1, ra.height) / 2), 2)
870
+ );
871
+ const db = Math.sqrt(
872
+ Math.pow(acx - (rb.left + Math.max(1, rb.width) / 2), 2) + Math.pow(acy - (rb.top + Math.max(1, rb.height) / 2), 2)
873
+ );
874
+ return da - db;
875
+ });
876
+ }
877
+ function relativeMany(target, actualRoot, outerRoot) {
878
+ if (!Object.prototype.hasOwnProperty.call(target, "root") || !Object.prototype.hasOwnProperty.call(target, "filters")) {
879
+ throw botError(
880
+ INVALID_ARGUMENT,
881
+ "Locator not suitable for relative locators: " + JSON.stringify(target)
882
+ );
883
+ }
884
+ const filters = target["filters"];
885
+ if (!Array.isArray(filters)) {
886
+ throw botError(INVALID_ARGUMENT, "Targets should be an array: " + JSON.stringify(target));
887
+ }
888
+ let elements;
889
+ const rootTarget = target["root"];
890
+ if (rootTarget instanceof Element) {
891
+ elements = [rootTarget];
892
+ } else {
893
+ elements = findElements(rootTarget, actualRoot);
894
+ }
895
+ if (!elements.length) {
896
+ return [];
897
+ }
898
+ const RELATIVE_STRATEGIES = {
899
+ above: (sel) => makeProximityFilter(sel, outerRoot, (a, c) => c.top + c.height <= a.top),
900
+ below: (sel) => makeProximityFilter(sel, outerRoot, (a, c) => c.top >= a.top + a.height),
901
+ left: (sel) => makeProximityFilter(sel, outerRoot, (a, c) => c.left + c.width <= a.left),
902
+ right: (sel) => makeProximityFilter(sel, outerRoot, (a, c) => c.left >= a.left + a.width),
903
+ near: (sel, distArg) => {
904
+ const distFromSelector = typeof sel["distance"] === "number" ? sel["distance"] : 0;
905
+ const distance = typeof distArg === "number" && distArg > 0 ? distArg : distFromSelector || 50;
906
+ return (candidate) => {
907
+ const anchor = resolveAnchor(sel, outerRoot);
908
+ if (anchor === candidate) return false;
909
+ const a = getClientRect2(anchor);
910
+ const c = getClientRect2(candidate);
911
+ const expanded = {
912
+ left: a.left - distance,
913
+ top: a.top - distance,
914
+ width: a.width + distance * 2,
915
+ height: a.height + distance * 2
916
+ };
917
+ return c.left < expanded.left + expanded.width && c.left + c.width > expanded.left && c.top < expanded.top + expanded.height && c.top + c.height > expanded.top;
918
+ };
919
+ },
920
+ straightAbove: (sel) => makeProximityFilter(
921
+ sel,
922
+ outerRoot,
923
+ (a, c) => c.left < a.left + a.width && c.left + c.width > a.left && c.top + c.height <= a.top
924
+ ),
925
+ straightBelow: (sel) => makeProximityFilter(
926
+ sel,
927
+ outerRoot,
928
+ (a, c) => c.left < a.left + a.width && c.left + c.width > a.left && c.top >= a.top + a.height
929
+ ),
930
+ straightLeft: (sel) => makeProximityFilter(
931
+ sel,
932
+ outerRoot,
933
+ (a, c) => c.top < a.top + a.height && c.top + c.height > a.top && c.left + c.width <= a.left
934
+ ),
935
+ straightRight: (sel) => makeProximityFilter(
936
+ sel,
937
+ outerRoot,
938
+ (a, c) => c.top < a.top + a.height && c.top + c.height > a.top && c.left >= a.left + a.width
939
+ )
940
+ };
941
+ const matched = elements.filter((el) => {
942
+ if (!el) return false;
943
+ return filters.every((filter) => {
944
+ const strategy = RELATIVE_STRATEGIES[filter.kind];
945
+ if (!strategy) {
946
+ throw botError(INVALID_ARGUMENT, "Cannot find filter suitable for " + filter.kind);
247
947
  }
248
- const lastAnchor = resolveAnchor(finalFilter.args[0]);
249
- return sortByProximity(lastAnchor, matched);
948
+ return strategy(...filter.args)(el);
949
+ });
950
+ });
951
+ const finalFilter = filters[filters.length - 1];
952
+ if (!finalFilter || !RELATIVE_STRATEGIES[finalFilter.kind]) {
953
+ return matched;
250
954
  }
955
+ const lastAnchor = resolveAnchor(finalFilter.args[0], outerRoot);
956
+ return sortByProximity(lastAnchor, matched);
957
+ }
958
+ function findElements(target, root) {
251
959
  const actualRoot = root || document;
252
- const keys = Object.keys(target).filter(k => Object.prototype.hasOwnProperty.call(target, k));
960
+ const keys = Object.keys(target).filter((k) => Object.prototype.hasOwnProperty.call(target, k));
253
961
  if (!keys.length) {
254
- throw botError(INVALID_ARGUMENT, 'Unsupported locator strategy: (empty)');
962
+ throw botError(INVALID_ARGUMENT, "Unsupported locator strategy: (empty)");
255
963
  }
256
964
  const key = keys[0];
257
965
  const value = target[key];
258
966
  switch (key) {
259
- case 'className':
260
- case 'class name':
261
- return classNameMany(value, actualRoot);
262
- case 'css':
263
- case 'css selector':
264
- return cssMany(value, actualRoot);
265
- case 'id':
266
- return idMany(value, actualRoot);
267
- case 'linkText':
268
- case 'link text':
269
- return linkTextMany(value, actualRoot, false);
270
- case 'partialLinkText':
271
- case 'partial link text':
272
- return linkTextMany(value, actualRoot, true);
273
- case 'name':
274
- return nameMany(value, actualRoot);
275
- case 'tagName':
276
- case 'tag name':
277
- return tagNameMany(value, actualRoot);
278
- case 'xpath':
279
- return xpathMany(value, actualRoot);
280
- case 'relative':
281
- return relativeMany(value, actualRoot);
282
- default:
283
- throw botError(INVALID_ARGUMENT, 'Unsupported locator strategy: ' + key);
284
- }
285
- }
286
- return findElements;
287
- })()
967
+ case "className":
968
+ case "class name":
969
+ return classNameMany(value, actualRoot);
970
+ case "css":
971
+ case "css selector":
972
+ return cssMany(value, actualRoot);
973
+ case "id":
974
+ return idMany(value, actualRoot);
975
+ case "linkText":
976
+ case "link text":
977
+ return linkTextMany(value, actualRoot, false);
978
+ case "partialLinkText":
979
+ case "partial link text":
980
+ return linkTextMany(value, actualRoot, true);
981
+ case "name":
982
+ return nameMany(value, actualRoot);
983
+ case "tagName":
984
+ case "tag name":
985
+ return tagNameMany(value, actualRoot);
986
+ case "xpath":
987
+ return xpathMany(value, actualRoot);
988
+ case "relative":
989
+ return relativeMany(value, actualRoot, root);
990
+ default:
991
+ throw botError(INVALID_ARGUMENT, "Unsupported locator strategy: " + key);
992
+ }
993
+ }
994
+ return __toCommonJS(find_elements_exports);
995
+ })();
996
+ return __seleniumAtom.default;
997
+ })()