ff-dom 1.0.18-beta.4 → 1.0.18-beta.5
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.
- package/package.json +1 -1
- package/src/utils/xpath.ts +34 -45
package/package.json
CHANGED
package/src/utils/xpath.ts
CHANGED
|
@@ -167,24 +167,21 @@ const getUniqueParentXpath = (
|
|
|
167
167
|
|
|
168
168
|
if (!reWhiteSpace.test(currentNode.textContent)) {
|
|
169
169
|
xpathe = isSvg(currentNode)
|
|
170
|
-
? `//*[local-name()='${
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
getFilteredText(currentNode)
|
|
179
|
-
)}]`;
|
|
170
|
+
? `//*[local-name()='${currentNode.tagName
|
|
171
|
+
}' and normalize-space(.)=${escapeCharacters(
|
|
172
|
+
getFilteredText(currentNode)
|
|
173
|
+
)}]`
|
|
174
|
+
: `//${currentNode.tagName || "*"
|
|
175
|
+
}[normalize-space(.)=${escapeCharacters(
|
|
176
|
+
getFilteredText(currentNode)
|
|
177
|
+
)}]`;
|
|
180
178
|
} else {
|
|
181
179
|
xpathe = isSvg(currentNode)
|
|
182
|
-
? `//*[local-name()='${
|
|
183
|
-
|
|
184
|
-
}' and .=${escapeCharacters(getFilteredText(currentNode))}]`
|
|
180
|
+
? `//*[local-name()='${currentNode.tagName
|
|
181
|
+
}' and .=${escapeCharacters(getFilteredText(currentNode))}]`
|
|
185
182
|
: `//${currentNode.tagName || "*"}[.=${escapeCharacters(
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
getFilteredText(currentNode)
|
|
184
|
+
)}]`;
|
|
188
185
|
}
|
|
189
186
|
|
|
190
187
|
const othersWithAttr = checkRelativeXpathRelation(
|
|
@@ -226,12 +223,11 @@ const getUniqueParentXpath = (
|
|
|
226
223
|
|
|
227
224
|
if (combinePattern?.length) {
|
|
228
225
|
const xpathe = isSvg(currentNode)
|
|
229
|
-
? `//*[local-name()='${
|
|
230
|
-
|
|
231
|
-
}' and ${combinePattern.join(" and ")}]`
|
|
226
|
+
? `//*[local-name()='${currentNode.tagName
|
|
227
|
+
}' and ${combinePattern.join(" and ")}]`
|
|
232
228
|
: `//${currentNode.tagName || "*"}[${combinePattern.join(
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
" and "
|
|
230
|
+
)}]`;
|
|
235
231
|
const othersWithAttr = checkRelativeXpathRelation(
|
|
236
232
|
xpathe,
|
|
237
233
|
nodeXpath,
|
|
@@ -263,7 +259,7 @@ const getUniqueParentXpath = (
|
|
|
263
259
|
}
|
|
264
260
|
|
|
265
261
|
// Final constructed XPath
|
|
266
|
-
const finalXPath = xpathParts.join("");
|
|
262
|
+
const finalXPath = xpathParts.join("") + nodeXpath;
|
|
267
263
|
let count = getCountOfXPath(finalXPath, domNode, docmt);
|
|
268
264
|
if (count === 1) {
|
|
269
265
|
parentXpathCache.set(domNode, finalXPath); // Cache final result
|
|
@@ -392,7 +388,7 @@ const getChildRelativeXpath = (
|
|
|
392
388
|
try {
|
|
393
389
|
do {
|
|
394
390
|
let uniqueAttrFound = false;
|
|
395
|
-
for (currentNode = st.pop()!; currentNode !== null;
|
|
391
|
+
for (currentNode = st.pop()!; currentNode !== null;) {
|
|
396
392
|
for (const attr of Array.from(currentNode.attributes)) {
|
|
397
393
|
if (checkBlockedAttributes(attr, currentNode, true)) {
|
|
398
394
|
let attrValue = attr.nodeValue;
|
|
@@ -745,12 +741,11 @@ const addRelativeXpaths = (
|
|
|
745
741
|
if (
|
|
746
742
|
relativeXpathIndex &&
|
|
747
743
|
getCountOfXPath(relativeXpathIndex, targetElemt, docmt) ===
|
|
748
|
-
|
|
744
|
+
1
|
|
749
745
|
) {
|
|
750
746
|
xpathData.push({
|
|
751
|
-
key: `relative xpath by relative parent ${
|
|
752
|
-
|
|
753
|
-
}`,
|
|
747
|
+
key: `relative xpath by relative parent ${isIndex ? "index" : ""
|
|
748
|
+
}`,
|
|
754
749
|
value: relativeXpathIndex,
|
|
755
750
|
});
|
|
756
751
|
}
|
|
@@ -759,18 +754,16 @@ const addRelativeXpaths = (
|
|
|
759
754
|
if (count < xpathDataWithIndex[0].count) {
|
|
760
755
|
xpathDataWithIndex.pop();
|
|
761
756
|
xpathDataWithIndex.push({
|
|
762
|
-
key: `relative xpath by relative parent ${
|
|
763
|
-
|
|
764
|
-
}`,
|
|
757
|
+
key: `relative xpath by relative parent ${isIndex ? "index" : ""
|
|
758
|
+
}`,
|
|
765
759
|
value: fullRelativeXpath,
|
|
766
760
|
count,
|
|
767
761
|
});
|
|
768
762
|
}
|
|
769
763
|
} else {
|
|
770
764
|
xpathDataWithIndex.push({
|
|
771
|
-
key: `relative xpath by relative parent ${
|
|
772
|
-
|
|
773
|
-
}`,
|
|
765
|
+
key: `relative xpath by relative parent ${isIndex ? "index" : ""
|
|
766
|
+
}`,
|
|
774
767
|
value: fullRelativeXpath,
|
|
775
768
|
count,
|
|
776
769
|
});
|
|
@@ -794,9 +787,8 @@ const addRelativeXpaths = (
|
|
|
794
787
|
relativeChildXpath.includes("text()") ||
|
|
795
788
|
relativeChildXpath.includes(".="))
|
|
796
789
|
) {
|
|
797
|
-
const fullRelativeXpath = `/${
|
|
798
|
-
|
|
799
|
-
}`;
|
|
790
|
+
const fullRelativeXpath = `/${nodeXpath[i] + relativeChildXpath.substring(1)
|
|
791
|
+
}`;
|
|
800
792
|
const count = getCountOfXPath(
|
|
801
793
|
fullRelativeXpath,
|
|
802
794
|
targetElemt,
|
|
@@ -818,12 +810,11 @@ const addRelativeXpaths = (
|
|
|
818
810
|
if (
|
|
819
811
|
relativeXpathIndex &&
|
|
820
812
|
getCountOfXPath(relativeXpathIndex, targetElemt, docmt) ===
|
|
821
|
-
|
|
813
|
+
1
|
|
822
814
|
) {
|
|
823
815
|
xpathData.push({
|
|
824
|
-
key: `relative xpath by relative parent ${
|
|
825
|
-
|
|
826
|
-
}`,
|
|
816
|
+
key: `relative xpath by relative parent ${isIndex ? "index" : ""
|
|
817
|
+
}`,
|
|
827
818
|
value: relativeXpathIndex,
|
|
828
819
|
});
|
|
829
820
|
}
|
|
@@ -832,18 +823,16 @@ const addRelativeXpaths = (
|
|
|
832
823
|
if (count < xpathDataWithIndex[0].count) {
|
|
833
824
|
xpathDataWithIndex.pop();
|
|
834
825
|
xpathDataWithIndex.push({
|
|
835
|
-
key: `relative xpath by relative child ${
|
|
836
|
-
|
|
837
|
-
}`,
|
|
826
|
+
key: `relative xpath by relative child ${isIndex ? "index" : ""
|
|
827
|
+
}`,
|
|
838
828
|
value: fullRelativeXpath,
|
|
839
829
|
count,
|
|
840
830
|
});
|
|
841
831
|
}
|
|
842
832
|
} else {
|
|
843
833
|
xpathDataWithIndex.push({
|
|
844
|
-
key: `relative xpath by relative child ${
|
|
845
|
-
|
|
846
|
-
}`,
|
|
834
|
+
key: `relative xpath by relative child ${isIndex ? "index" : ""
|
|
835
|
+
}`,
|
|
847
836
|
value: fullRelativeXpath,
|
|
848
837
|
count,
|
|
849
838
|
});
|