ff-dom 1.0.18-beta.1 → 1.0.18-beta.3

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.
@@ -1,13 +1,11 @@
1
1
  import { parseDOM } from "./xpath.ts";
2
2
  import {
3
3
  findXpathWithIndex,
4
- findRoot,
5
4
  getShadowRoot,
6
5
  getTextContent,
7
6
  escapeCharacters,
8
7
  getCountOfXPath,
9
8
  checkBlockedAttributes,
10
- isNumberExist,
11
9
  getAbsoluteXPath,
12
10
  isSvg,
13
11
  getCombinationXpath,
@@ -17,14 +15,12 @@ import {
17
15
  getReferenceElementsXpath,
18
16
  getRelativeXPath,
19
17
  findMatchingParenthesis,
20
- removeParenthesis,
21
- modifiedElementAttributes
18
+ removeParenthesis
22
19
  } from "./xpathHelpers.ts";
23
20
 
24
21
  let xpathDataWithIndex: any[] = [];
25
22
  let xpathData: { key: string; value: string }[] = [];
26
23
  const reWhiteSpace = /^[\S]+( [\S]+)*$/gi;
27
- let multiElementReferenceMode: boolean = false;
28
24
 
29
25
  export const findRelativeXpath = (
30
26
  element1: HTMLElement | Element,
@@ -32,7 +28,8 @@ export const findRelativeXpath = (
32
28
  docmt: Document,
33
29
  xpaths1: any[],
34
30
  xpaths2: any[],
35
- isIndex: any
31
+ isIndex: boolean,
32
+ multiElementReferenceMode: boolean = false
36
33
  ) => {
37
34
  // debugger;
38
35
  const par1 = element1.parentElement;
@@ -40,7 +37,6 @@ export const findRelativeXpath = (
40
37
  let rel_xpath: any[] = [];
41
38
 
42
39
  let tempElement;
43
- const root = findRoot(element1);
44
40
  let finalXpaths: any[] = [];
45
41
 
46
42
  if (isIndex) {
@@ -74,7 +70,8 @@ export const findRelativeXpath = (
74
70
  "self",
75
71
  xpaths1,
76
72
  xpaths2,
77
- isIndex
73
+ isIndex,
74
+ multiElementReferenceMode
78
75
  );
79
76
  if (rel_xpath) finalXpaths = finalXpaths.concat(rel_xpath);
80
77
  }
@@ -89,7 +86,8 @@ export const findRelativeXpath = (
89
86
  "parent",
90
87
  xpaths1,
91
88
  xpaths2,
92
- isIndex
89
+ isIndex,
90
+ multiElementReferenceMode
93
91
  );
94
92
  if (rel_xpath) finalXpaths = finalXpaths.concat(rel_xpath);
95
93
  }
@@ -105,7 +103,8 @@ export const findRelativeXpath = (
105
103
  "ancestor",
106
104
  xpaths1,
107
105
  xpaths2,
108
- isIndex
106
+ isIndex,
107
+ multiElementReferenceMode
109
108
  );
110
109
  if (rel_xpath) {
111
110
  finalXpaths = finalXpaths.concat(rel_xpath);
@@ -126,7 +125,8 @@ export const findRelativeXpath = (
126
125
  "ancestor-or-self",
127
126
  xpaths1,
128
127
  xpaths2,
129
- isIndex
128
+ isIndex,
129
+ multiElementReferenceMode
130
130
  );
131
131
  if (rel_xpath) {
132
132
  finalXpaths = finalXpaths.concat(rel_xpath);
@@ -151,7 +151,8 @@ export const findRelativeXpath = (
151
151
  "following-sibling",
152
152
  xpaths1,
153
153
  xpaths2,
154
- isIndex
154
+ isIndex,
155
+ multiElementReferenceMode
155
156
  );
156
157
  if (rel_xpath) {
157
158
  finalXpaths = finalXpaths.concat(rel_xpath);
@@ -172,7 +173,8 @@ export const findRelativeXpath = (
172
173
  "preceding-sibling",
173
174
  xpaths1,
174
175
  xpaths2,
175
- isIndex
176
+ isIndex,
177
+ multiElementReferenceMode
176
178
  );
177
179
  if (rel_xpath) {
178
180
  finalXpaths = finalXpaths.concat(rel_xpath);
@@ -192,7 +194,8 @@ export const findRelativeXpath = (
192
194
  "child",
193
195
  xpaths1,
194
196
  xpaths2,
195
- isIndex
197
+ isIndex,
198
+ multiElementReferenceMode
196
199
  );
197
200
  if (rel_xpath) {
198
201
  finalXpaths = finalXpaths.concat(rel_xpath);
@@ -211,7 +214,8 @@ export const findRelativeXpath = (
211
214
  "preceding",
212
215
  xpaths1,
213
216
  xpaths2,
214
- isIndex
217
+ isIndex,
218
+ multiElementReferenceMode
215
219
  );
216
220
  }
217
221
 
@@ -222,7 +226,8 @@ export const findRelativeXpath = (
222
226
  "following",
223
227
  xpaths1,
224
228
  xpaths2,
225
- isIndex
229
+ isIndex,
230
+ multiElementReferenceMode
226
231
  );
227
232
  }
228
233
  if (rel_xpath) {
@@ -235,7 +240,8 @@ export const findRelativeXpath = (
235
240
  xpaths1,
236
241
  xpaths2,
237
242
  "descendant",
238
- isIndex
243
+ isIndex,
244
+ multiElementReferenceMode
239
245
  );
240
246
  if (descendantXpath) finalXpaths = finalXpaths.concat(descendantXpath);
241
247
 
@@ -245,7 +251,8 @@ export const findRelativeXpath = (
245
251
  xpaths1,
246
252
  xpaths2,
247
253
  "descedant-or-self",
248
- isIndex
254
+ isIndex,
255
+ multiElementReferenceMode
249
256
  );
250
257
  if (descendantSelfXpath) {
251
258
  finalXpaths = finalXpaths.concat(descendantSelfXpath);
@@ -274,7 +281,8 @@ const descendantExpression = (
274
281
  isIndex: any,
275
282
  expCommonParentXpathElements: string | any[],
276
283
  step4: string,
277
- refCommonParentXpathElementLength: number
284
+ refCommonParentXpathElementLength: number = 0,
285
+ multiElementReferenceMode: boolean = false
278
286
  ) => {
279
287
  let finalExpectedElementXpath: string | undefined = "";
280
288
 
@@ -282,7 +290,7 @@ const descendantExpression = (
282
290
  xpath2.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length >=
283
291
  expCommonParentXpathElements.length
284
292
  ) {
285
- const xpaths2Els = [];
293
+ const xpaths2Els: string[] = [];
286
294
  const xpath2Elements = xpath2.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);
287
295
  for (let x = 1; x <= expCommonParentXpathElements.length; x++) {
288
296
  xpaths2Els.unshift(
@@ -304,7 +312,8 @@ const descendantExpression = (
304
312
  refExpectElement,
305
313
  docmt,
306
314
  relation,
307
- isIndex
315
+ isIndex,
316
+ multiElementReferenceMode
308
317
  );
309
318
  if (traverseXpath) {
310
319
  return traverseXpath;
@@ -365,7 +374,8 @@ const getDescendantXpath = (
365
374
  xpaths1: { key: string; value: string }[],
366
375
  xpaths2: { key: string; value: string }[],
367
376
  relation: "descendant" | "descedant-or-self",
368
- isIndex: boolean
377
+ isIndex: boolean = false,
378
+ multiElementReferenceMode: boolean = false
369
379
  ) => {
370
380
  const refElement: HTMLElement | Element = refExpectElement[refExpectElement.length - 2];
371
381
  const expElement: HTMLElement | Element = refExpectElement[refExpectElement.length - 1];
@@ -413,7 +423,7 @@ const getDescendantXpath = (
413
423
  }
414
424
  }
415
425
 
416
- const expCommonParentXpathElements = [];
426
+ const expCommonParentXpathElements: string[] = [];
417
427
  for (
418
428
  let j =
419
429
  relation === "descendant" ? parentElementNumber : parentElementNumber - 1;
@@ -488,15 +498,16 @@ const getDescendantXpath = (
488
498
  isIndex,
489
499
  expCommonParentXpathElements,
490
500
  step4,
491
- refCommonParentXpathElementLength
501
+ refCommonParentXpathElementLength,
502
+ multiElementReferenceMode
492
503
  );
493
504
  }
494
505
  }
495
506
  }
496
507
 
497
508
  if (refExpectElement[refExpectElement.length - 2].attributes) {
498
- for (const attrName of refExpectElement[refExpectElement.length - 2]
499
- .attributes) {
509
+ for (const attrName of Array.from(refExpectElement[refExpectElement.length - 2]
510
+ .attributes)) {
500
511
  if (
501
512
  checkBlockedAttributes(attrName, refExpectElement[refExpectElement.length - 2], false)
502
513
  ) {
@@ -539,15 +550,16 @@ const getDescendantXpath = (
539
550
  isIndex,
540
551
  expCommonParentXpathElements,
541
552
  step4,
542
- refCommonParentXpathElementLength
553
+ refCommonParentXpathElementLength,
554
+ multiElementReferenceMode
543
555
  );
544
556
  }
545
557
  }
546
558
  }
547
559
  }
548
560
 
549
- for (const attrName of refExpectElement[refExpectElement.length - 2]
550
- .attributes) {
561
+ for (const attrName of Array.from(refExpectElement[refExpectElement.length - 2]
562
+ .attributes)) {
551
563
  if (
552
564
  checkBlockedAttributes(attrName, refExpectElement[refExpectElement.length - 2], false)
553
565
  ) {
@@ -595,7 +607,8 @@ const getDescendantXpath = (
595
607
  isIndex,
596
608
  expCommonParentXpathElements,
597
609
  step4,
598
- refCommonParentXpathElementLength
610
+ refCommonParentXpathElementLength,
611
+ multiElementReferenceMode
599
612
  );
600
613
  }
601
614
  }
@@ -614,12 +627,13 @@ const getDescendantXpath = (
614
627
  ? "]".repeat(refCommonParentXpathElementLength)
615
628
  : "")
616
629
  }`,
617
- expCommonParentXpathElements.reverse(),
630
+ expCommonParentXpathElements,
618
631
  refExpectElement[refExpectElement.length - 1],
619
632
  refExpectElement,
620
633
  docmt,
621
634
  relation,
622
- isIndex
635
+ isIndex,
636
+ multiElementReferenceMode
623
637
  );
624
638
  if (traverseXpath) {
625
639
  return traverseXpath;
@@ -632,7 +646,8 @@ const getXpathRelationExpression = (
632
646
  relation: string,
633
647
  xpath1: any[],
634
648
  xpath2: any[],
635
- isIndex: any
649
+ isIndex: boolean,
650
+ multiElementReferenceMode: boolean
636
651
  ) => {
637
652
  let xpaths1;
638
653
  let xpaths2;
@@ -716,7 +731,7 @@ const getXpathRelationExpression = (
716
731
  ? xpaths2[j].value
717
732
  : xpaths2[j].value.substring(xpaths2[j].value.indexOf("//") + 2)
718
733
  }`;
719
- const xpath2Elements = tempPath.split(
734
+ const xpath2Elements: string[] = tempPath.split(
720
735
  /\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g
721
736
  );
722
737
  if (xpath2Elements.length > 1) {
@@ -735,7 +750,8 @@ const getXpathRelationExpression = (
735
750
  [element1, element2],
736
751
  element2.ownerDocument,
737
752
  relation,
738
- isIndex
753
+ isIndex,
754
+ multiElementReferenceMode
739
755
  );
740
756
 
741
757
  console.log('getXpathRelationExpression traverseXpath', traverseXpath)
@@ -787,7 +803,7 @@ const getReferenceElementXpath = (element: HTMLElement | Element) => {
787
803
  xpaths1 = [
788
804
  {
789
805
  key: "",
790
- value: getRelativeXPath(element, element.ownerDocument, false, false, [...element.attributes]),
806
+ value: getRelativeXPath(element, element.ownerDocument, false, false, Array.from(element.attributes)),
791
807
  },
792
808
  ];
793
809
  }
@@ -796,7 +812,7 @@ const getReferenceElementXpath = (element: HTMLElement | Element) => {
796
812
  xpaths1 = [
797
813
  {
798
814
  key: "",
799
- value: getRelativeXPath(element, element.ownerDocument, true, false, [...element.attributes]),
815
+ value: getRelativeXPath(element, element.ownerDocument, true, false, Array.from(element.attributes)),
800
816
  },
801
817
  ];
802
818
  xpaths1 = xpaths1?.map((x) =>
@@ -836,52 +852,16 @@ const getReferenceElementXpath = (element: HTMLElement | Element) => {
836
852
 
837
853
  const getTraverseXpathExpression = (
838
854
  xpathe1: string,
839
- absoluteXpathElements: any[],
855
+ absoluteXpathElements: string[],
840
856
  element2: HTMLElement | Element,
841
857
  refExpectElement: Array<HTMLElement | Element>,
842
858
  docmt: Node,
843
859
  relation: string,
844
- isIndex: any
860
+ isIndex: boolean,
861
+ multiElementReferenceMode: boolean
845
862
  ) => {
846
- let finalExpectedElementXpath: string | undefined
847
- if (multiElementReferenceMode) {
848
- const xpath2 = absoluteXpathElements.join("/");
849
- finalExpectedElementXpath = `//${xpathe1}/${relation}::${replaceActualAttributes(
850
- xpath2,
851
- element2
852
- )}`;
853
- const rel_count = getCountOfXPath(
854
- finalExpectedElementXpath,
855
- element2,
856
- docmt
857
- );
858
- if (rel_count === 1) {
859
- return [
860
- {
861
- key: `dynamic ${relation}`,
862
- value: replaceTempAttributes(finalExpectedElementXpath),
863
- },
864
- ];
865
- }
866
- if (rel_count > 1) {
867
- if (isIndex) {
868
- finalExpectedElementXpath = findXpathWithIndex(
869
- finalExpectedElementXpath,
870
- refExpectElement[refExpectElement.length - 1],
871
- docmt,
872
- rel_count
873
- );
874
- if (finalExpectedElementXpath) {
875
- return [
876
- {
877
- key: `dynamic ${relation}${isIndex ? " index" : ""}`,
878
- value: replaceTempAttributes(finalExpectedElementXpath),
879
- },
880
- ];
881
- }
882
- }
883
- }
884
- } else {
863
+ let finalExpectedElementXpath: string | undefined;
864
+ if (!multiElementReferenceMode) {
885
865
  for (let x = 1; x <= absoluteXpathElements.length; x++) {
886
866
  const xpath2 = absoluteXpathElements
887
867
  .slice(absoluteXpathElements.length - x, absoluteXpathElements.length)
@@ -922,6 +902,43 @@ const getTraverseXpathExpression = (
922
902
  }
923
903
  }
924
904
  }
905
+ } else {
906
+ const xpath2 = absoluteXpathElements.join("/");
907
+ finalExpectedElementXpath = `//${xpathe1}/${relation}::${replaceActualAttributes(
908
+ xpath2,
909
+ element2
910
+ )}`;
911
+ const rel_count = getCountOfXPath(
912
+ finalExpectedElementXpath,
913
+ element2,
914
+ docmt
915
+ );
916
+ if (rel_count === 1) {
917
+ return [
918
+ {
919
+ key: `dynamic ${relation}`,
920
+ value: replaceTempAttributes(finalExpectedElementXpath),
921
+ },
922
+ ];
923
+ }
924
+ if (rel_count > 1) {
925
+ if (isIndex) {
926
+ finalExpectedElementXpath = findXpathWithIndex(
927
+ finalExpectedElementXpath,
928
+ refExpectElement[refExpectElement.length - 1],
929
+ docmt,
930
+ rel_count
931
+ );
932
+ if (finalExpectedElementXpath) {
933
+ return [
934
+ {
935
+ key: `dynamic ${relation}${isIndex ? " index" : ""}`,
936
+ value: replaceTempAttributes(finalExpectedElementXpath),
937
+ },
938
+ ];
939
+ }
940
+ }
941
+ }
925
942
  }
926
943
  };
927
944
 
@@ -127,7 +127,7 @@ const getUniqueParentXpath = (
127
127
 
128
128
  while (currentNode && currentNode.nodeType === 1) {
129
129
  const hasUniqueAttr = false;
130
- for (const attrName of currentNode.attributes) {
130
+ for (const attrName of Array.from(currentNode.attributes)) {
131
131
  if (checkBlockedAttributes(attrName, currentNode, isTarget)) {
132
132
  let attrValue = attrName.nodeValue;
133
133
 
@@ -299,7 +299,7 @@ const getParentRelativeXpath = (
299
299
 
300
300
  // BASE CASE #2: Check for unique attributes
301
301
  let uniqueAttrFound = false;
302
- for (const attr of currentNode.attributes) {
302
+ for (const attr of Array.from(currentNode.attributes)) {
303
303
  if (checkBlockedAttributes(attr, currentNode, isTarget)) {
304
304
  let attrValue = attr.nodeValue;
305
305
 
@@ -393,7 +393,7 @@ const getChildRelativeXpath = (
393
393
  do {
394
394
  let uniqueAttrFound = false;
395
395
  for (currentNode = st.pop()!; currentNode !== null; ) {
396
- for (const attr of currentNode.attributes) {
396
+ for (const attr of Array.from(currentNode.attributes)) {
397
397
  if (checkBlockedAttributes(attr, currentNode, true)) {
398
398
  let attrValue = attr.nodeValue;
399
399
 
@@ -522,7 +522,7 @@ const processSibling = (
522
522
  ) => {
523
523
  try {
524
524
  if (sibling.hasAttributes()) {
525
- for (const attr of sibling.attributes) {
525
+ for (const attr of Array.from(sibling.attributes)) {
526
526
  let xpathe = intermediateXpathStep(
527
527
  sibling,
528
528
  {
@@ -1055,13 +1055,15 @@ export const parseDOM = (
1055
1055
  const docmt = targetElemt?.ownerDocument || doc;
1056
1056
  const tag = targetElemt.tagName;
1057
1057
  const { attributes } = targetElemt;
1058
- addAllXPathAttributes([...attributes], targetElemt, docmt, isIndex, isTarget);
1058
+ addAllXPathAttributes(Array.from(attributes), targetElemt, docmt, isIndex, isTarget);
1059
1059
  if (!referenceElementMode) {
1060
1060
  if (xpathData.length) {
1061
1061
  const len = xpathData.length;
1062
1062
  for (let i = 0; i < len; i++) {
1063
1063
  let xpth = xpathData[i].value;
1064
- xpth = xpth.replace(tag, "*");
1064
+ xpth = "//*" + xpth.substring(
1065
+ xpth.indexOf("//") + 2 + tag.length
1066
+ );
1065
1067
  const count = getCountOfXPath(xpth, element, docmt);
1066
1068
  if (count === 1) {
1067
1069
  xpathData.push({
@@ -1080,7 +1082,7 @@ export const parseDOM = (
1080
1082
  docmt,
1081
1083
  isIndex,
1082
1084
  isTarget,
1083
- [...targetElemt.attributes]
1085
+ Array.from(targetElemt.attributes)
1084
1086
  );
1085
1087
  }
1086
1088
 
@@ -1,7 +1,6 @@
1
1
  export const reWhiteSpace = /^[\S]+( [\S]+)*$/gi;
2
- let cspEnabled: boolean = false;
2
+ export let cspEnabled: boolean = false;
3
3
  const xpathCache: { [x: string]: number } = {};
4
- let multiElementReferenceMode: boolean = false;
5
4
  let relativeXPathCache = new Map();
6
5
  export let modifiedElementAttributes: {
7
6
  url: string | null;
@@ -67,7 +66,7 @@ export const buildPattern = (
67
66
  pattern: string,
68
67
  isSvg: boolean,
69
68
  tagName: string
70
- ) => {
69
+ ): string => {
71
70
  return isSvg
72
71
  ? `//*[local-name()='${tagName}' and ${pattern}]`
73
72
  : `//${tagName}[${pattern}]`;
@@ -99,15 +98,16 @@ export const getTextContent = (
99
98
  return "";
100
99
  };
101
100
 
102
- export const getFilteredText = (element: Node) => {
101
+ export const getFilteredText = (element: Node): string => {
103
102
  return element?.childNodes[0]?.nodeValue || "";
104
103
  };
105
104
 
106
105
  export const getCountOfXPath = (
107
106
  xpath: string,
108
107
  element: HTMLElement | Element,
109
- docmt: Node
110
- ) => {
108
+ docmt: Node,
109
+ multiElementReferenceMode: boolean = false
110
+ ): number => {
111
111
  try {
112
112
  let count;
113
113
  // Check if result is cached
@@ -160,7 +160,7 @@ export const getCountOfXPath = (
160
160
  }
161
161
  };
162
162
 
163
- export const escapeCharacters = (text: string) => {
163
+ export const escapeCharacters = (text: string): string => {
164
164
  if (text) {
165
165
  if (!(text.indexOf('"') === -1)) {
166
166
  return `'${text}'`;
@@ -172,7 +172,7 @@ export const escapeCharacters = (text: string) => {
172
172
  return `'${text}'`;
173
173
  };
174
174
 
175
- export const removeParenthesis = (xpath: string) => {
175
+ export const removeParenthesis = (xpath: string): string => {
176
176
  const charArr = xpath.split("");
177
177
 
178
178
  let count = charArr.length;
@@ -243,12 +243,12 @@ export const findXpathWithIndex = (
243
243
  }
244
244
  };
245
245
 
246
- const deleteLineGap = (a: string) => {
246
+ const deleteLineGap = (a: string): string => {
247
247
  a &&= a.split("\n")[0].length > 0 ? a.split("\n")[0] : a.split("\n")[1];
248
248
  return a;
249
249
  };
250
250
 
251
- const deleteGarbageFromInnerText = (a: string) => {
251
+ const deleteGarbageFromInnerText = (a: string): string => {
252
252
  a = deleteLineGap(a);
253
253
  a = a
254
254
  .split(/[^\u0000-\u00ff]/)
@@ -259,7 +259,7 @@ const deleteGarbageFromInnerText = (a: string) => {
259
259
  return (a = a.split("/")[0].trim());
260
260
  };
261
261
 
262
- export const replaceWhiteSpaces = (str: string) => {
262
+ export const replaceWhiteSpaces = (str: string): string => {
263
263
  if (str) {
264
264
  return str.replace(/\s\s+/g, " ").trim();
265
265
  }
@@ -267,7 +267,7 @@ export const replaceWhiteSpaces = (str: string) => {
267
267
  return str;
268
268
  };
269
269
 
270
- export const getShadowRoot = (a: HTMLElement | Element) => {
270
+ export const getShadowRoot = (a: HTMLElement | Element): Element | null => {
271
271
  for (a = a && a.parentElement!; a; ) {
272
272
  if (a.toString() === "[object ShadowRoot]") return a;
273
273
  a = a.parentElement!;
@@ -282,7 +282,7 @@ export const checkBlockedAttributes = (
282
282
  },
283
283
  targetElement: HTMLElement | Element,
284
284
  isTarget: boolean
285
- ) => {
285
+ ): boolean => {
286
286
  if (
287
287
  !attribute?.value ||
288
288
  typeof attribute?.value === "boolean" ||
@@ -308,7 +308,7 @@ export const checkBlockedAttributes = (
308
308
  return true;
309
309
  };
310
310
 
311
- export const getRelationship = (a: HTMLElement, b: HTMLElement) => {
311
+ export const getRelationship = (a: HTMLElement, b: HTMLElement): string => {
312
312
  let pos = a.compareDocumentPosition(b);
313
313
  return pos === 2
314
314
  ? "preceding"
@@ -323,14 +323,6 @@ export const getRelationship = (a: HTMLElement, b: HTMLElement) => {
323
323
  : "";
324
324
  };
325
325
 
326
- export const findRoot = (node: Node) => {
327
- while (node && node.parentNode) {
328
- node = node.parentNode;
329
- }
330
-
331
- return node;
332
- };
333
-
334
326
  export const isSvg = (element: HTMLElement | Element) => {
335
327
  return element instanceof SVGElement;
336
328
  };
@@ -654,10 +646,10 @@ export const getRelativeXPath = (
654
646
  while (currentNode) {
655
647
  let xpathe: string | undefined = "";
656
648
  let hasUniqueAttr = false;
657
- let attributes = domNode === currentNode ? attributesArray : currentNode.attributes
649
+ let attributes = domNode === currentNode ? attributesArray ?? currentNode.attributes : currentNode.attributes
658
650
 
659
651
  // Loop through attributes to check for unique identifiers
660
- for (const attrName of attributes) {
652
+ for (const attrName of Array.from(attributes)) {
661
653
  if (checkBlockedAttributes(attrName, currentNode, isTarget)) {
662
654
  let attrValue = attrName.nodeValue;
663
655
 
@@ -880,7 +872,7 @@ export const getAttributeCombinationXpath = (
880
872
  docmt: Document,
881
873
  uniqueAttributes: Attr[],
882
874
  isTarget: boolean
883
- ) => {
875
+ ): string | undefined => {
884
876
  try {
885
877
  const xpathAttributes = [];
886
878
 
@@ -971,7 +963,7 @@ export const intermediateXpathStep = (
971
963
  export const getFilteredTextXPath = (
972
964
  node: HTMLElement | Element,
973
965
  docmt: Document
974
- ) => {
966
+ ): string => {
975
967
  if (!node.textContent) return "";
976
968
 
977
969
  const filteredText = getFilteredText(node);
@@ -997,7 +989,7 @@ export const getFilteredTextXPath = (
997
989
  return xpathe;
998
990
  };
999
991
 
1000
- export const getTextXpathFunction = (domNode: HTMLElement | Element) => {
992
+ export const getTextXpathFunction = (domNode: HTMLElement | Element): string | undefined => {
1001
993
  const trimmedText = getTextContent(domNode)?.trim();
1002
994
  const filteredText = trimmedText
1003
995
  ? escapeCharacters(deleteGarbageFromInnerText(trimmedText))
@@ -1014,7 +1006,7 @@ export const getXpathString = (
1014
1006
  node: HTMLElement | Element,
1015
1007
  attrName: string,
1016
1008
  attrValue: string
1017
- ) => {
1009
+ ): string => {
1018
1010
  const reWhiteSpace = new RegExp(/^[\S]+( [\S]+)*$/gi);
1019
1011
  let xpathe: string = "";
1020
1012
 
@@ -1052,7 +1044,7 @@ export const getXpathString = (
1052
1044
  export const replaceActualAttributes = (
1053
1045
  str: string,
1054
1046
  element: { attributes: any }
1055
- ) => {
1047
+ ): string => {
1056
1048
  if (str) {
1057
1049
  return str.replace(/\bdisabled\b/gi, "flndisabled");
1058
1050
  }
@@ -1064,7 +1056,7 @@ const addAttributeSplitCombineXpaths = (
1064
1056
  targetElemt: HTMLElement | Element,
1065
1057
  docmt: Document,
1066
1058
  isTarget: boolean
1067
- ) => {
1059
+ ): { key: string; value: string }[] => {
1068
1060
  const attributesArray = Array.prototype.slice.call(attributes);
1069
1061
  const xpaths: { key: string; value: string }[] = [];
1070
1062
  try {
@@ -1090,7 +1082,7 @@ export const getReferenceElementsXpath = (
1090
1082
  domNode: HTMLElement | Element,
1091
1083
  docmt: Document,
1092
1084
  isTarget: boolean
1093
- ) => {
1085
+ ): { key: string; value: string }[] => {
1094
1086
  let nodeXpath1;
1095
1087
  const xpaths1 = [];
1096
1088
  if (
@@ -1119,7 +1111,7 @@ export const getReferenceElementsXpath = (
1119
1111
  }
1120
1112
 
1121
1113
  if (domNode.attributes) {
1122
- for (const attrName of domNode.attributes) {
1114
+ for (const attrName of Array.from(domNode.attributes)) {
1123
1115
  if (checkBlockedAttributes(attrName, domNode, isTarget)) {
1124
1116
  let attrValue = attrName.nodeValue;
1125
1117
  if (attrValue) {
@@ -1232,7 +1224,7 @@ export const getReferenceElementsXpath = (
1232
1224
  return xpaths1;
1233
1225
  };
1234
1226
 
1235
- export function parseXml(xmlStr: string) {
1227
+ export const parseXml = (xmlStr: string): Document | null => {
1236
1228
  if (window.DOMParser) {
1237
1229
  return new window.DOMParser().parseFromString(xmlStr, "text/xml");
1238
1230
  }
@@ -1296,4 +1288,5 @@ export const xpathUtils = {
1296
1288
  startObserver,
1297
1289
  stopObserver,
1298
1290
  modifiedElementAttributes,
1291
+ cspEnabled
1299
1292
  };
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "esnext",
4
- "lib": ["dom", "ESNext"],
4
+ "lib": ["dom", "dom.iterable", "ESNext"],
5
5
  "moduleResolution": "bundler",
6
6
  "module": "esnext",
7
7
  "allowImportingTsExtensions": true,