ff-dom 1.0.18-beta.2 → 1.0.18-beta.4
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/dist/index.browser.cjs +72 -36
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +72 -36
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cdn.js +72 -36
- package/dist/types/browser/browser/xpath.d.ts +8 -7
- package/dist/types/browser/utils/referenceXpath.d.ts +5 -5
- package/dist/types/browser/utils/xpathHelpers.d.ts +8 -7
- package/package.json +1 -1
- package/src/utils/getElementsFromHTML.ts +12 -13
- package/src/utils/referenceXpath.ts +89 -72
- package/src/utils/xpath.ts +3 -1
- package/src/utils/xpathHelpers.ts +23 -30
- package/tsconfig.json +1 -1
package/dist/index.cdn.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const reWhiteSpace$1 = /^[\S]+( [\S]+)*$/gi;
|
|
5
|
+
let cspEnabled = false;
|
|
5
6
|
const xpathCache$1 = {};
|
|
6
|
-
let multiElementReferenceMode = false;
|
|
7
7
|
let relativeXPathCache = new Map();
|
|
8
8
|
let modifiedElementAttributes$1 = [];
|
|
9
9
|
let mutationObserver;
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
const getFilteredText = (element) => {
|
|
63
63
|
return element?.childNodes[0]?.nodeValue || "";
|
|
64
64
|
};
|
|
65
|
-
const getCountOfXPath = (xpath, element, docmt) => {
|
|
65
|
+
const getCountOfXPath = (xpath, element, docmt, multiElementReferenceMode = false) => {
|
|
66
66
|
try {
|
|
67
67
|
let count;
|
|
68
68
|
// Check if result is cached
|
|
@@ -76,7 +76,23 @@
|
|
|
76
76
|
count = owner.evaluate(`count(${xpath})`, docmt, null, XPathResult.NUMBER_TYPE, null).numberValue;
|
|
77
77
|
xpathCache$1[xpath] = count;
|
|
78
78
|
}
|
|
79
|
-
if (multiElementReferenceMode && Array.isArray(element))
|
|
79
|
+
if (multiElementReferenceMode && Array.isArray(element)) {
|
|
80
|
+
if (count > 1) {
|
|
81
|
+
const elementsFromXpath = getElementFromXpath(xpath, docmt, true);
|
|
82
|
+
let nodex, matchedCount = 0;
|
|
83
|
+
if (elementsFromXpath instanceof XPathResult) {
|
|
84
|
+
while ((nodex = elementsFromXpath?.iterateNext())) {
|
|
85
|
+
if (element.includes(nodex)) {
|
|
86
|
+
matchedCount += 1;
|
|
87
|
+
if (matchedCount === 2)
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (matchedCount !== 2)
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
80
96
|
else {
|
|
81
97
|
// Short-circuit if we only need to match one element
|
|
82
98
|
if (count === 1) {
|
|
@@ -215,12 +231,6 @@
|
|
|
215
231
|
? "self"
|
|
216
232
|
: "";
|
|
217
233
|
};
|
|
218
|
-
const findRoot = (node) => {
|
|
219
|
-
while (node && node.parentNode) {
|
|
220
|
-
node = node.parentNode;
|
|
221
|
-
}
|
|
222
|
-
return node;
|
|
223
|
-
};
|
|
224
234
|
const isSvg = (element) => {
|
|
225
235
|
return element instanceof SVGElement;
|
|
226
236
|
};
|
|
@@ -858,12 +868,12 @@
|
|
|
858
868
|
}
|
|
859
869
|
return xpaths1;
|
|
860
870
|
};
|
|
861
|
-
|
|
871
|
+
const parseXml = (xmlStr) => {
|
|
862
872
|
if (window.DOMParser) {
|
|
863
873
|
return new window.DOMParser().parseFromString(xmlStr, "text/xml");
|
|
864
874
|
}
|
|
865
875
|
return null;
|
|
866
|
-
}
|
|
876
|
+
};
|
|
867
877
|
const normalizeXPath = (xpath) => {
|
|
868
878
|
// Replace text() = "value" or text()='value'
|
|
869
879
|
xpath = xpath.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g, "normalize-space(.)=$1$2$1");
|
|
@@ -911,6 +921,7 @@
|
|
|
911
921
|
startObserver,
|
|
912
922
|
stopObserver,
|
|
913
923
|
modifiedElementAttributes: modifiedElementAttributes$1,
|
|
924
|
+
cspEnabled
|
|
914
925
|
};
|
|
915
926
|
|
|
916
927
|
let xpathData$1 = [];
|
|
@@ -1620,7 +1631,7 @@
|
|
|
1620
1631
|
const len = xpathData$1.length;
|
|
1621
1632
|
for (let i = 0; i < len; i++) {
|
|
1622
1633
|
let xpth = xpathData$1[i].value;
|
|
1623
|
-
xpth = xpth.
|
|
1634
|
+
xpth = "//*" + xpth.substring(xpth.indexOf("//") + 2 + tag.length);
|
|
1624
1635
|
const count = getCountOfXPath(xpth, element, docmt);
|
|
1625
1636
|
if (count === 1) {
|
|
1626
1637
|
xpathData$1.push({
|
|
@@ -1655,13 +1666,12 @@
|
|
|
1655
1666
|
let xpathDataWithIndex = [];
|
|
1656
1667
|
let xpathData = [];
|
|
1657
1668
|
const reWhiteSpace = /^[\S]+( [\S]+)*$/gi;
|
|
1658
|
-
const findRelativeXpath = (element1, element2, docmt, xpaths1, xpaths2, isIndex) => {
|
|
1669
|
+
const findRelativeXpath = (element1, element2, docmt, xpaths1, xpaths2, isIndex, multiElementReferenceMode = false) => {
|
|
1659
1670
|
// debugger;
|
|
1660
1671
|
const par1 = element1.parentElement;
|
|
1661
1672
|
const par2 = element2.parentElement;
|
|
1662
1673
|
let rel_xpath = [];
|
|
1663
1674
|
let tempElement;
|
|
1664
|
-
findRoot(element1);
|
|
1665
1675
|
let finalXpaths = [];
|
|
1666
1676
|
if (isIndex) {
|
|
1667
1677
|
if (xpathDataWithIndex.length) {
|
|
@@ -1681,14 +1691,14 @@
|
|
|
1681
1691
|
// both are same
|
|
1682
1692
|
if (element1.isSameNode(element2)) {
|
|
1683
1693
|
// rel_xpath = xpath1 + "/self::" + element1.tagName;
|
|
1684
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "self", xpaths1, xpaths2, isIndex);
|
|
1694
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "self", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1685
1695
|
if (rel_xpath)
|
|
1686
1696
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1687
1697
|
}
|
|
1688
1698
|
// parent
|
|
1689
1699
|
tempElement = element1.parentElement;
|
|
1690
1700
|
if (tempElement === element2) {
|
|
1691
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "parent", xpaths1, xpaths2, isIndex);
|
|
1701
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "parent", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1692
1702
|
if (rel_xpath)
|
|
1693
1703
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1694
1704
|
}
|
|
@@ -1696,7 +1706,7 @@
|
|
|
1696
1706
|
tempElement = element1.parentElement;
|
|
1697
1707
|
while (tempElement !== null) {
|
|
1698
1708
|
if (tempElement === element2) {
|
|
1699
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "ancestor", xpaths1, xpaths2, isIndex);
|
|
1709
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "ancestor", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1700
1710
|
if (rel_xpath) {
|
|
1701
1711
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1702
1712
|
break;
|
|
@@ -1708,7 +1718,7 @@
|
|
|
1708
1718
|
tempElement = element1;
|
|
1709
1719
|
do {
|
|
1710
1720
|
if (tempElement === element2) {
|
|
1711
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "ancestor-or-self", xpaths1, xpaths2, isIndex);
|
|
1721
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "ancestor-or-self", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1712
1722
|
if (rel_xpath) {
|
|
1713
1723
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1714
1724
|
break;
|
|
@@ -1720,7 +1730,7 @@
|
|
|
1720
1730
|
if (par1?.isSameNode(par2)) {
|
|
1721
1731
|
for (let m = element1.nextElementSibling; m != null; m = m.nextElementSibling) {
|
|
1722
1732
|
if (m != null && m.isSameNode(element2)) {
|
|
1723
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "following-sibling", xpaths1, xpaths2, isIndex);
|
|
1733
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "following-sibling", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1724
1734
|
if (rel_xpath) {
|
|
1725
1735
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1726
1736
|
break;
|
|
@@ -1729,7 +1739,7 @@
|
|
|
1729
1739
|
}
|
|
1730
1740
|
for (let n = element1.previousElementSibling; n != null; n = n.previousElementSibling) {
|
|
1731
1741
|
if (n != null && n.isSameNode(element2)) {
|
|
1732
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "preceding-sibling", xpaths1, xpaths2, isIndex);
|
|
1742
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "preceding-sibling", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1733
1743
|
if (rel_xpath) {
|
|
1734
1744
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1735
1745
|
break;
|
|
@@ -1741,7 +1751,7 @@
|
|
|
1741
1751
|
if (element1?.children?.length) {
|
|
1742
1752
|
for (let m = element1.children[0]; m !== null; m = m?.nextElementSibling) {
|
|
1743
1753
|
if (m === element2) {
|
|
1744
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "child", xpaths1, xpaths2, isIndex);
|
|
1754
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "child", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1745
1755
|
if (rel_xpath) {
|
|
1746
1756
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1747
1757
|
break;
|
|
@@ -1752,18 +1762,18 @@
|
|
|
1752
1762
|
// following
|
|
1753
1763
|
const relation = element1.compareDocumentPosition(element2);
|
|
1754
1764
|
if (relation === 2) {
|
|
1755
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "preceding", xpaths1, xpaths2, isIndex);
|
|
1765
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "preceding", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1756
1766
|
}
|
|
1757
1767
|
if (relation === 4) {
|
|
1758
|
-
rel_xpath = getXpathRelationExpression(element1, element2, "following", xpaths1, xpaths2, isIndex);
|
|
1768
|
+
rel_xpath = getXpathRelationExpression(element1, element2, "following", xpaths1, xpaths2, isIndex, multiElementReferenceMode);
|
|
1759
1769
|
}
|
|
1760
1770
|
if (rel_xpath) {
|
|
1761
1771
|
finalXpaths = finalXpaths.concat(rel_xpath);
|
|
1762
1772
|
}
|
|
1763
|
-
const descendantXpath = getDescendantXpath([element1, element2], docmt, xpaths1, xpaths2, "descendant", isIndex);
|
|
1773
|
+
const descendantXpath = getDescendantXpath([element1, element2], docmt, xpaths1, xpaths2, "descendant", isIndex, multiElementReferenceMode);
|
|
1764
1774
|
if (descendantXpath)
|
|
1765
1775
|
finalXpaths = finalXpaths.concat(descendantXpath);
|
|
1766
|
-
const descendantSelfXpath = getDescendantXpath([element1, element2], docmt, xpaths1, xpaths2, "descedant-or-self", isIndex);
|
|
1776
|
+
const descendantSelfXpath = getDescendantXpath([element1, element2], docmt, xpaths1, xpaths2, "descedant-or-self", isIndex, multiElementReferenceMode);
|
|
1767
1777
|
if (descendantSelfXpath) {
|
|
1768
1778
|
finalXpaths = finalXpaths.concat(descendantSelfXpath);
|
|
1769
1779
|
}
|
|
@@ -1780,7 +1790,7 @@
|
|
|
1780
1790
|
return [finalXpaths[0]];
|
|
1781
1791
|
}
|
|
1782
1792
|
};
|
|
1783
|
-
const descendantExpression = (refExpectElement, xpath2, relation, docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength) => {
|
|
1793
|
+
const descendantExpression = (refExpectElement, xpath2, relation, docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength = 0, multiElementReferenceMode = false) => {
|
|
1784
1794
|
let finalExpectedElementXpath = "";
|
|
1785
1795
|
if (xpath2.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length >=
|
|
1786
1796
|
expCommonParentXpathElements.length) {
|
|
@@ -1794,7 +1804,7 @@
|
|
|
1794
1804
|
const traverseXpath = getTraverseXpathExpression(`${step4 +
|
|
1795
1805
|
(refCommonParentXpathElementLength
|
|
1796
1806
|
? "]".repeat(refCommonParentXpathElementLength)
|
|
1797
|
-
: "")}`, xpaths2Els, refExpectElement[refExpectElement.length - 1], refExpectElement, docmt, relation, isIndex);
|
|
1807
|
+
: "")}`, xpaths2Els, refExpectElement[refExpectElement.length - 1], refExpectElement, docmt, relation, isIndex, multiElementReferenceMode);
|
|
1798
1808
|
if (traverseXpath) {
|
|
1799
1809
|
return traverseXpath;
|
|
1800
1810
|
}
|
|
@@ -1831,7 +1841,7 @@
|
|
|
1831
1841
|
}
|
|
1832
1842
|
}
|
|
1833
1843
|
};
|
|
1834
|
-
const getDescendantXpath = (refExpectElement, docmt, xpaths1, xpaths2, relation, isIndex) => {
|
|
1844
|
+
const getDescendantXpath = (refExpectElement, docmt, xpaths1, xpaths2, relation, isIndex = false, multiElementReferenceMode = false) => {
|
|
1835
1845
|
const refElement = refExpectElement[refExpectElement.length - 2];
|
|
1836
1846
|
const expElement = refExpectElement[refExpectElement.length - 1];
|
|
1837
1847
|
const expElementDocmnt = getShadowRoot(expElement) ?? expElement.ownerDocument;
|
|
@@ -1895,7 +1905,7 @@
|
|
|
1895
1905
|
xpath2 = xpathData[i].value; // No need to modify the value
|
|
1896
1906
|
}
|
|
1897
1907
|
if (xpath2) {
|
|
1898
|
-
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength);
|
|
1908
|
+
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength, multiElementReferenceMode);
|
|
1899
1909
|
}
|
|
1900
1910
|
}
|
|
1901
1911
|
}
|
|
@@ -1922,7 +1932,7 @@
|
|
|
1922
1932
|
else {
|
|
1923
1933
|
xpath2 = xpathData[i].value; // No need to modify the value
|
|
1924
1934
|
}
|
|
1925
|
-
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength);
|
|
1935
|
+
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength, multiElementReferenceMode);
|
|
1926
1936
|
}
|
|
1927
1937
|
}
|
|
1928
1938
|
}
|
|
@@ -1953,7 +1963,7 @@
|
|
|
1953
1963
|
else {
|
|
1954
1964
|
xpath2 = xpathData[i].value; // No need to modify the value
|
|
1955
1965
|
}
|
|
1956
|
-
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength);
|
|
1966
|
+
return descendantExpression(refExpectElement, xpath2, relation, expElementDocmnt || docmt, isIndex, expCommonParentXpathElements, step4, refCommonParentXpathElementLength, multiElementReferenceMode);
|
|
1957
1967
|
}
|
|
1958
1968
|
}
|
|
1959
1969
|
}
|
|
@@ -1966,12 +1976,12 @@
|
|
|
1966
1976
|
const traverseXpath = getTraverseXpathExpression(`${step4 +
|
|
1967
1977
|
(refCommonParentXpathElementLength
|
|
1968
1978
|
? "]".repeat(refCommonParentXpathElementLength)
|
|
1969
|
-
: "")}`, expCommonParentXpathElements
|
|
1979
|
+
: "")}`, expCommonParentXpathElements, refExpectElement[refExpectElement.length - 1], refExpectElement, docmt, relation, isIndex, multiElementReferenceMode);
|
|
1970
1980
|
if (traverseXpath) {
|
|
1971
1981
|
return traverseXpath;
|
|
1972
1982
|
}
|
|
1973
1983
|
};
|
|
1974
|
-
const getXpathRelationExpression = (element1, element2, relation, xpath1, xpath2, isIndex) => {
|
|
1984
|
+
const getXpathRelationExpression = (element1, element2, relation, xpath1, xpath2, isIndex, multiElementReferenceMode) => {
|
|
1975
1985
|
let xpaths1;
|
|
1976
1986
|
let xpaths2;
|
|
1977
1987
|
console.log('getXpathRelationExpression', relation);
|
|
@@ -2038,7 +2048,7 @@
|
|
|
2038
2048
|
if (xpath2Elements.length > 1) {
|
|
2039
2049
|
const traverseXpath = getTraverseXpathExpression(`${xpaths1[i].value.indexOf("//") !== 0
|
|
2040
2050
|
? replaceActualAttributes(xpaths1[i].value, element1)
|
|
2041
|
-
: replaceActualAttributes(xpaths1[i].value.substring(xpaths1[i].value.indexOf("//") + 2), element1)}`, xpath2Elements, element2, [element1, element2], element2.ownerDocument, relation, isIndex);
|
|
2051
|
+
: replaceActualAttributes(xpaths1[i].value.substring(xpaths1[i].value.indexOf("//") + 2), element1)}`, xpath2Elements, element2, [element1, element2], element2.ownerDocument, relation, isIndex, multiElementReferenceMode);
|
|
2042
2052
|
console.log('getXpathRelationExpression traverseXpath', traverseXpath);
|
|
2043
2053
|
if (traverseXpath) {
|
|
2044
2054
|
finalXpaths.concat(traverseXpath);
|
|
@@ -2111,9 +2121,9 @@
|
|
|
2111
2121
|
});
|
|
2112
2122
|
return xpaths1;
|
|
2113
2123
|
};
|
|
2114
|
-
const getTraverseXpathExpression = (xpathe1, absoluteXpathElements, element2, refExpectElement, docmt, relation, isIndex) => {
|
|
2124
|
+
const getTraverseXpathExpression = (xpathe1, absoluteXpathElements, element2, refExpectElement, docmt, relation, isIndex, multiElementReferenceMode) => {
|
|
2115
2125
|
let finalExpectedElementXpath;
|
|
2116
|
-
{
|
|
2126
|
+
if (!multiElementReferenceMode) {
|
|
2117
2127
|
for (let x = 1; x <= absoluteXpathElements.length; x++) {
|
|
2118
2128
|
const xpath2 = absoluteXpathElements
|
|
2119
2129
|
.slice(absoluteXpathElements.length - x, absoluteXpathElements.length)
|
|
@@ -2143,6 +2153,32 @@
|
|
|
2143
2153
|
}
|
|
2144
2154
|
}
|
|
2145
2155
|
}
|
|
2156
|
+
else {
|
|
2157
|
+
const xpath2 = absoluteXpathElements.join("/");
|
|
2158
|
+
finalExpectedElementXpath = `//${xpathe1}/${relation}::${replaceActualAttributes(xpath2)}`;
|
|
2159
|
+
const rel_count = getCountOfXPath(finalExpectedElementXpath, element2, docmt);
|
|
2160
|
+
if (rel_count === 1) {
|
|
2161
|
+
return [
|
|
2162
|
+
{
|
|
2163
|
+
key: `dynamic ${relation}`,
|
|
2164
|
+
value: replaceTempAttributes(finalExpectedElementXpath),
|
|
2165
|
+
},
|
|
2166
|
+
];
|
|
2167
|
+
}
|
|
2168
|
+
if (rel_count > 1) {
|
|
2169
|
+
if (isIndex) {
|
|
2170
|
+
finalExpectedElementXpath = findXpathWithIndex(finalExpectedElementXpath, refExpectElement[refExpectElement.length - 1], docmt, rel_count);
|
|
2171
|
+
if (finalExpectedElementXpath) {
|
|
2172
|
+
return [
|
|
2173
|
+
{
|
|
2174
|
+
key: `dynamic ${relation}${isIndex ? " index" : ""}`,
|
|
2175
|
+
value: replaceTempAttributes(finalExpectedElementXpath),
|
|
2176
|
+
},
|
|
2177
|
+
];
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2146
2182
|
};
|
|
2147
2183
|
const referenceXpath = {
|
|
2148
2184
|
findRelativeXpath,
|
|
@@ -20,22 +20,22 @@ export declare const createXPathAPI: () => {
|
|
|
20
20
|
checkRelativeXpathRelation: (nodeXpath1: string, nodeXpath2: string, targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, relationType: string) => string | null;
|
|
21
21
|
};
|
|
22
22
|
referenceXpaths: {
|
|
23
|
-
findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex:
|
|
23
|
+
findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex: boolean, multiElementReferenceMode?: boolean) => any[] | undefined;
|
|
24
24
|
getDescendantXpath: (refExpectElement: Array<HTMLElement | Element>, docmt: Document, xpaths1: {
|
|
25
25
|
key: string;
|
|
26
26
|
value: string;
|
|
27
27
|
}[], xpaths2: {
|
|
28
28
|
key: string;
|
|
29
29
|
value: string;
|
|
30
|
-
}[], relation: "descendant" | "descedant-or-self", isIndex
|
|
30
|
+
}[], relation: "descendant" | "descedant-or-self", isIndex?: boolean, multiElementReferenceMode?: boolean) => {
|
|
31
31
|
key: string;
|
|
32
32
|
value: string;
|
|
33
33
|
}[] | undefined;
|
|
34
|
-
getXpathRelationExpression: (element1: HTMLElement | Element, element2: HTMLElement | Element, relation: string, xpath1: any[], xpath2: any[], isIndex:
|
|
34
|
+
getXpathRelationExpression: (element1: HTMLElement | Element, element2: HTMLElement | Element, relation: string, xpath1: any[], xpath2: any[], isIndex: boolean, multiElementReferenceMode: boolean) => {
|
|
35
35
|
key: string;
|
|
36
36
|
value: any;
|
|
37
37
|
}[];
|
|
38
|
-
getTraverseXpathExpression: (xpathe1: string, absoluteXpathElements:
|
|
38
|
+
getTraverseXpathExpression: (xpathe1: string, absoluteXpathElements: string[], element2: HTMLElement | Element, refExpectElement: Array<HTMLElement | Element>, docmt: Node, relation: string, isIndex: boolean, multiElementReferenceMode: boolean) => {
|
|
39
39
|
key: string;
|
|
40
40
|
value: string;
|
|
41
41
|
}[] | undefined;
|
|
@@ -45,7 +45,7 @@ export declare const createXPathAPI: () => {
|
|
|
45
45
|
}[];
|
|
46
46
|
};
|
|
47
47
|
xpathUtils: {
|
|
48
|
-
parseXml:
|
|
48
|
+
parseXml: (xmlStr: string) => Document | null;
|
|
49
49
|
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
50
50
|
key: string;
|
|
51
51
|
value: string;
|
|
@@ -59,7 +59,7 @@ export declare const createXPathAPI: () => {
|
|
|
59
59
|
findXpathWithIndex: (val: string, node: HTMLElement | Element, docmt: Node, count: number) => string | undefined;
|
|
60
60
|
isNumberExist: (str: string) => boolean;
|
|
61
61
|
getTextContent: (targetElement: HTMLElement | Element) => string;
|
|
62
|
-
getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node) => number;
|
|
62
|
+
getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node, multiElementReferenceMode?: boolean) => number;
|
|
63
63
|
normalizeXPath: (xpath: string) => string;
|
|
64
64
|
getShadowRoot: (a: HTMLElement | Element) => Element | null;
|
|
65
65
|
escapeCharacters: (text: string) => string;
|
|
@@ -68,7 +68,7 @@ export declare const createXPathAPI: () => {
|
|
|
68
68
|
name: string;
|
|
69
69
|
value: string;
|
|
70
70
|
}, targetElement: HTMLElement | Element, isTarget: boolean) => boolean;
|
|
71
|
-
getRelationship: (a: HTMLElement, b: HTMLElement) =>
|
|
71
|
+
getRelationship: (a: HTMLElement, b: HTMLElement) => string;
|
|
72
72
|
findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
73
73
|
deleteGarbageFromInnerText: (a: string) => string;
|
|
74
74
|
replaceTempAttributes: (str: string) => string;
|
|
@@ -81,6 +81,7 @@ export declare const createXPathAPI: () => {
|
|
|
81
81
|
element: HTMLElement | Element;
|
|
82
82
|
doc: Document;
|
|
83
83
|
}[];
|
|
84
|
+
cspEnabled: boolean;
|
|
84
85
|
};
|
|
85
86
|
getElementsFromHTML: (record: import("../types/locator.ts").ElementRecord, docmt: Document) => {
|
|
86
87
|
[key: string]: any;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export declare const findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex:
|
|
1
|
+
export declare const findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex: boolean, multiElementReferenceMode?: boolean) => any[] | undefined;
|
|
2
2
|
declare const referenceXpath: {
|
|
3
|
-
findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex:
|
|
3
|
+
findRelativeXpath: (element1: HTMLElement | Element, element2: HTMLElement | Element, docmt: Document, xpaths1: any[], xpaths2: any[], isIndex: boolean, multiElementReferenceMode?: boolean) => any[] | undefined;
|
|
4
4
|
getDescendantXpath: (refExpectElement: Array<HTMLElement | Element>, docmt: Document, xpaths1: {
|
|
5
5
|
key: string;
|
|
6
6
|
value: string;
|
|
7
7
|
}[], xpaths2: {
|
|
8
8
|
key: string;
|
|
9
9
|
value: string;
|
|
10
|
-
}[], relation: "descendant" | "descedant-or-self", isIndex
|
|
10
|
+
}[], relation: "descendant" | "descedant-or-self", isIndex?: boolean, multiElementReferenceMode?: boolean) => {
|
|
11
11
|
key: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}[] | undefined;
|
|
14
|
-
getXpathRelationExpression: (element1: HTMLElement | Element, element2: HTMLElement | Element, relation: string, xpath1: any[], xpath2: any[], isIndex:
|
|
14
|
+
getXpathRelationExpression: (element1: HTMLElement | Element, element2: HTMLElement | Element, relation: string, xpath1: any[], xpath2: any[], isIndex: boolean, multiElementReferenceMode: boolean) => {
|
|
15
15
|
key: string;
|
|
16
16
|
value: any;
|
|
17
17
|
}[];
|
|
18
|
-
getTraverseXpathExpression: (xpathe1: string, absoluteXpathElements:
|
|
18
|
+
getTraverseXpathExpression: (xpathe1: string, absoluteXpathElements: string[], element2: HTMLElement | Element, refExpectElement: Array<HTMLElement | Element>, docmt: Node, relation: string, isIndex: boolean, multiElementReferenceMode: boolean) => {
|
|
19
19
|
key: string;
|
|
20
20
|
value: string;
|
|
21
21
|
}[] | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const reWhiteSpace: RegExp;
|
|
2
|
+
export declare let cspEnabled: boolean;
|
|
2
3
|
export declare let modifiedElementAttributes: {
|
|
3
4
|
url: string | null;
|
|
4
5
|
attributeName: string | null;
|
|
@@ -12,7 +13,7 @@ export declare const isNumberExist: (str: string) => boolean;
|
|
|
12
13
|
export declare const buildPattern: (pattern: string, isSvg: boolean, tagName: string) => string;
|
|
13
14
|
export declare const getTextContent: (targetElement: HTMLElement | Element) => string;
|
|
14
15
|
export declare const getFilteredText: (element: Node) => string;
|
|
15
|
-
export declare const getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node) => number;
|
|
16
|
+
export declare const getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node, multiElementReferenceMode?: boolean) => number;
|
|
16
17
|
export declare const escapeCharacters: (text: string) => string;
|
|
17
18
|
export declare const removeParenthesis: (xpath: string) => string;
|
|
18
19
|
export declare const findXpathWithIndex: (val: string, node: HTMLElement | Element, docmt: Node, count: number) => string | undefined;
|
|
@@ -22,8 +23,7 @@ export declare const checkBlockedAttributes: (attribute: {
|
|
|
22
23
|
name: string;
|
|
23
24
|
value: string;
|
|
24
25
|
}, targetElement: HTMLElement | Element, isTarget: boolean) => boolean;
|
|
25
|
-
export declare const getRelationship: (a: HTMLElement, b: HTMLElement) =>
|
|
26
|
-
export declare const findRoot: (node: Node) => Node;
|
|
26
|
+
export declare const getRelationship: (a: HTMLElement, b: HTMLElement) => string;
|
|
27
27
|
export declare const isSvg: (element: HTMLElement | Element) => element is SVGElement;
|
|
28
28
|
export declare const replaceTempAttributes: (str: string) => string;
|
|
29
29
|
export declare const getPropertyXPath: (element: HTMLElement | Element, docmt: Document, prop: string, value: string, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
@@ -45,11 +45,11 @@ export declare const getReferenceElementsXpath: (domNode: HTMLElement | Element,
|
|
|
45
45
|
key: string;
|
|
46
46
|
value: string;
|
|
47
47
|
}[];
|
|
48
|
-
export declare
|
|
48
|
+
export declare const parseXml: (xmlStr: string) => Document | null;
|
|
49
49
|
export declare const normalizeXPath: (xpath: string) => string;
|
|
50
50
|
export declare const findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
51
51
|
export declare const xpathUtils: {
|
|
52
|
-
parseXml:
|
|
52
|
+
parseXml: (xmlStr: string) => Document | null;
|
|
53
53
|
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
54
54
|
key: string;
|
|
55
55
|
value: string;
|
|
@@ -63,7 +63,7 @@ export declare const xpathUtils: {
|
|
|
63
63
|
findXpathWithIndex: (val: string, node: HTMLElement | Element, docmt: Node, count: number) => string | undefined;
|
|
64
64
|
isNumberExist: (str: string) => boolean;
|
|
65
65
|
getTextContent: (targetElement: HTMLElement | Element) => string;
|
|
66
|
-
getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node) => number;
|
|
66
|
+
getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node, multiElementReferenceMode?: boolean) => number;
|
|
67
67
|
normalizeXPath: (xpath: string) => string;
|
|
68
68
|
getShadowRoot: (a: HTMLElement | Element) => Element | null;
|
|
69
69
|
escapeCharacters: (text: string) => string;
|
|
@@ -72,7 +72,7 @@ export declare const xpathUtils: {
|
|
|
72
72
|
name: string;
|
|
73
73
|
value: string;
|
|
74
74
|
}, targetElement: HTMLElement | Element, isTarget: boolean) => boolean;
|
|
75
|
-
getRelationship: (a: HTMLElement, b: HTMLElement) =>
|
|
75
|
+
getRelationship: (a: HTMLElement, b: HTMLElement) => string;
|
|
76
76
|
findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
77
77
|
deleteGarbageFromInnerText: (a: string) => string;
|
|
78
78
|
replaceTempAttributes: (str: string) => string;
|
|
@@ -85,4 +85,5 @@ export declare const xpathUtils: {
|
|
|
85
85
|
element: HTMLElement | Element;
|
|
86
86
|
doc: Document;
|
|
87
87
|
}[];
|
|
88
|
+
cspEnabled: boolean;
|
|
88
89
|
};
|
package/package.json
CHANGED
|
@@ -408,19 +408,18 @@ const getElementsFromHTML = (
|
|
|
408
408
|
});
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
:
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
: "Y",
|
|
411
|
+
const xpathResults = parseDOM(targetElement, document, false, true);
|
|
412
|
+
xpathResults.forEach((result) => {
|
|
413
|
+
const fnValue = result.value;
|
|
414
|
+
record.locators.forEach((loc) => {
|
|
415
|
+
createLocator(loc, {
|
|
416
|
+
name: 'xpath',
|
|
417
|
+
value: fnValue,
|
|
418
|
+
isRecorded: loc.value === fnValue ? loc.isRecorded : 'Y',
|
|
419
|
+
isSelfHealed: loc.value === fnValue ? loc.isSelfHealed : 'Y',
|
|
420
|
+
});
|
|
422
421
|
});
|
|
423
|
-
})
|
|
422
|
+
})
|
|
424
423
|
|
|
425
424
|
for (const locator of record.locators) {
|
|
426
425
|
try {
|
|
@@ -440,7 +439,7 @@ const getElementsFromHTML = (
|
|
|
440
439
|
value: relativeXpath,
|
|
441
440
|
isRecorded:
|
|
442
441
|
locator.isRecorded !== "" &&
|
|
443
|
-
|
|
442
|
+
locator.isRecorded !== null
|
|
444
443
|
? locator.isRecorded
|
|
445
444
|
: "Y",
|
|
446
445
|
});
|