@midscene/shared 0.17.2-beta-20250522144134.0 → 0.17.2
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/es/extractor.js +7 -8
- package/dist/lib/extractor.js +7 -8
- package/dist/script/htmlElement.js +7 -8
- package/package.json +1 -1
- package/src/extractor/locator.ts +10 -10
package/dist/es/extractor.js
CHANGED
|
@@ -849,11 +849,11 @@ var getTextNodeIndex = (textNode) => {
|
|
|
849
849
|
}
|
|
850
850
|
return index;
|
|
851
851
|
};
|
|
852
|
-
var getElementXPath = (element
|
|
852
|
+
var getElementXPath = (element) => {
|
|
853
853
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
854
854
|
const parentNode = element.parentNode;
|
|
855
855
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
856
|
-
const parentXPath = getElementXPath(parentNode
|
|
856
|
+
const parentXPath = getElementXPath(parentNode);
|
|
857
857
|
const textIndex = getTextNodeIndex(element);
|
|
858
858
|
return `${parentXPath}/text()[${textIndex}]`;
|
|
859
859
|
}
|
|
@@ -868,11 +868,11 @@ var getElementXPath = (element, fullPath = false) => {
|
|
|
868
868
|
if (el === document.body) {
|
|
869
869
|
return "/html/body";
|
|
870
870
|
}
|
|
871
|
-
if (el.id
|
|
871
|
+
if (el.id) {
|
|
872
872
|
return `//*[@id="${el.id}"]`;
|
|
873
873
|
}
|
|
874
|
-
const ancestorWithId =
|
|
875
|
-
if (ancestorWithId
|
|
874
|
+
const ancestorWithId = findFirstAncestorWithId(el);
|
|
875
|
+
if (ancestorWithId) {
|
|
876
876
|
const ancestorPath = `//*[@id="${ancestorWithId.id}"]`;
|
|
877
877
|
let current = el;
|
|
878
878
|
const pathParts = [];
|
|
@@ -890,7 +890,7 @@ var getElementXPath = (element, fullPath = false) => {
|
|
|
890
890
|
const index = getElementIndex(el);
|
|
891
891
|
const tagName = el.nodeName.toLowerCase();
|
|
892
892
|
if (el.parentNode) {
|
|
893
|
-
const parentXPath = getElementXPath(el.parentNode
|
|
893
|
+
const parentXPath = getElementXPath(el.parentNode);
|
|
894
894
|
return `${parentXPath}/${tagName}[${index}]`;
|
|
895
895
|
}
|
|
896
896
|
return `/${tagName}[${index}]`;
|
|
@@ -899,8 +899,7 @@ function generateXPaths(node) {
|
|
|
899
899
|
if (!node)
|
|
900
900
|
return [];
|
|
901
901
|
const xPath = getElementXPath(node);
|
|
902
|
-
|
|
903
|
-
return [xPath, fullXPath];
|
|
902
|
+
return [xPath];
|
|
904
903
|
}
|
|
905
904
|
function getXpathsById(id) {
|
|
906
905
|
const node = getNodeFromCacheList(id);
|
package/dist/lib/extractor.js
CHANGED
|
@@ -886,11 +886,11 @@ var getTextNodeIndex = (textNode) => {
|
|
|
886
886
|
}
|
|
887
887
|
return index;
|
|
888
888
|
};
|
|
889
|
-
var getElementXPath = (element
|
|
889
|
+
var getElementXPath = (element) => {
|
|
890
890
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
891
891
|
const parentNode = element.parentNode;
|
|
892
892
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
893
|
-
const parentXPath = getElementXPath(parentNode
|
|
893
|
+
const parentXPath = getElementXPath(parentNode);
|
|
894
894
|
const textIndex = getTextNodeIndex(element);
|
|
895
895
|
return `${parentXPath}/text()[${textIndex}]`;
|
|
896
896
|
}
|
|
@@ -905,11 +905,11 @@ var getElementXPath = (element, fullPath = false) => {
|
|
|
905
905
|
if (el === document.body) {
|
|
906
906
|
return "/html/body";
|
|
907
907
|
}
|
|
908
|
-
if (el.id
|
|
908
|
+
if (el.id) {
|
|
909
909
|
return `//*[@id="${el.id}"]`;
|
|
910
910
|
}
|
|
911
|
-
const ancestorWithId =
|
|
912
|
-
if (ancestorWithId
|
|
911
|
+
const ancestorWithId = findFirstAncestorWithId(el);
|
|
912
|
+
if (ancestorWithId) {
|
|
913
913
|
const ancestorPath = `//*[@id="${ancestorWithId.id}"]`;
|
|
914
914
|
let current = el;
|
|
915
915
|
const pathParts = [];
|
|
@@ -927,7 +927,7 @@ var getElementXPath = (element, fullPath = false) => {
|
|
|
927
927
|
const index = getElementIndex(el);
|
|
928
928
|
const tagName = el.nodeName.toLowerCase();
|
|
929
929
|
if (el.parentNode) {
|
|
930
|
-
const parentXPath = getElementXPath(el.parentNode
|
|
930
|
+
const parentXPath = getElementXPath(el.parentNode);
|
|
931
931
|
return `${parentXPath}/${tagName}[${index}]`;
|
|
932
932
|
}
|
|
933
933
|
return `/${tagName}[${index}]`;
|
|
@@ -936,8 +936,7 @@ function generateXPaths(node) {
|
|
|
936
936
|
if (!node)
|
|
937
937
|
return [];
|
|
938
938
|
const xPath = getElementXPath(node);
|
|
939
|
-
|
|
940
|
-
return [xPath, fullXPath];
|
|
939
|
+
return [xPath];
|
|
941
940
|
}
|
|
942
941
|
function getXpathsById(id) {
|
|
943
942
|
const node = getNodeFromCacheList(id);
|
|
@@ -1441,11 +1441,11 @@ ${indentStr}${after}`;
|
|
|
1441
1441
|
}
|
|
1442
1442
|
return index;
|
|
1443
1443
|
};
|
|
1444
|
-
var getElementXPath = (element
|
|
1444
|
+
var getElementXPath = (element) => {
|
|
1445
1445
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
1446
1446
|
const parentNode = element.parentNode;
|
|
1447
1447
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
1448
|
-
const parentXPath = getElementXPath(parentNode
|
|
1448
|
+
const parentXPath = getElementXPath(parentNode);
|
|
1449
1449
|
const textIndex = getTextNodeIndex(element);
|
|
1450
1450
|
return `${parentXPath}/text()[${textIndex}]`;
|
|
1451
1451
|
}
|
|
@@ -1460,11 +1460,11 @@ ${indentStr}${after}`;
|
|
|
1460
1460
|
if (el === document.body) {
|
|
1461
1461
|
return "/html/body";
|
|
1462
1462
|
}
|
|
1463
|
-
if (el.id
|
|
1463
|
+
if (el.id) {
|
|
1464
1464
|
return `//*[@id="${el.id}"]`;
|
|
1465
1465
|
}
|
|
1466
|
-
const ancestorWithId =
|
|
1467
|
-
if (ancestorWithId
|
|
1466
|
+
const ancestorWithId = findFirstAncestorWithId(el);
|
|
1467
|
+
if (ancestorWithId) {
|
|
1468
1468
|
const ancestorPath = `//*[@id="${ancestorWithId.id}"]`;
|
|
1469
1469
|
let current = el;
|
|
1470
1470
|
const pathParts = [];
|
|
@@ -1482,7 +1482,7 @@ ${indentStr}${after}`;
|
|
|
1482
1482
|
const index = getElementIndex(el);
|
|
1483
1483
|
const tagName = el.nodeName.toLowerCase();
|
|
1484
1484
|
if (el.parentNode) {
|
|
1485
|
-
const parentXPath = getElementXPath(el.parentNode
|
|
1485
|
+
const parentXPath = getElementXPath(el.parentNode);
|
|
1486
1486
|
return `${parentXPath}/${tagName}[${index}]`;
|
|
1487
1487
|
}
|
|
1488
1488
|
return `/${tagName}[${index}]`;
|
|
@@ -1491,8 +1491,7 @@ ${indentStr}${after}`;
|
|
|
1491
1491
|
if (!node)
|
|
1492
1492
|
return [];
|
|
1493
1493
|
const xPath = getElementXPath(node);
|
|
1494
|
-
|
|
1495
|
-
return [xPath, fullXPath];
|
|
1494
|
+
return [xPath];
|
|
1496
1495
|
}
|
|
1497
1496
|
function getXpathsById(id) {
|
|
1498
1497
|
const node = getNodeFromCacheList(id);
|
package/package.json
CHANGED
package/src/extractor/locator.ts
CHANGED
|
@@ -46,13 +46,13 @@ const getTextNodeIndex = (textNode: Node): number => {
|
|
|
46
46
|
return index;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
const getElementXPath = (element: Node
|
|
49
|
+
const getElementXPath = (element: Node): string => {
|
|
50
50
|
// deal with text node
|
|
51
51
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
52
52
|
// get parent node xpath
|
|
53
53
|
const parentNode = element.parentNode;
|
|
54
54
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
55
|
-
const parentXPath = getElementXPath(parentNode
|
|
55
|
+
const parentXPath = getElementXPath(parentNode);
|
|
56
56
|
const textIndex = getTextNodeIndex(element);
|
|
57
57
|
return `${parentXPath}/text()[${textIndex}]`;
|
|
58
58
|
}
|
|
@@ -72,14 +72,14 @@ const getElementXPath = (element: Node, fullPath = false): string => {
|
|
|
72
72
|
return '/html/body';
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// If this element has an ID
|
|
76
|
-
if (el.id
|
|
75
|
+
// If this element has an ID, return an XPath with the ID
|
|
76
|
+
if (el.id) {
|
|
77
77
|
return `//*[@id="${el.id}"]`;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const ancestorWithId =
|
|
80
|
+
const ancestorWithId = findFirstAncestorWithId(el);
|
|
81
81
|
|
|
82
|
-
if (ancestorWithId
|
|
82
|
+
if (ancestorWithId) {
|
|
83
83
|
// Start from the ancestor with ID
|
|
84
84
|
const ancestorPath = `//*[@id="${ancestorWithId.id}"]`;
|
|
85
85
|
|
|
@@ -100,7 +100,8 @@ const getElementXPath = (element: Node, fullPath = false): string => {
|
|
|
100
100
|
: ancestorPath;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
// If no parent node,
|
|
103
|
+
// If no parent node, or we need a full path and haven't returned yet,
|
|
104
|
+
// start building the full path
|
|
104
105
|
if (!el.parentNode) {
|
|
105
106
|
return `/${el.nodeName.toLowerCase()}`;
|
|
106
107
|
}
|
|
@@ -109,7 +110,7 @@ const getElementXPath = (element: Node, fullPath = false): string => {
|
|
|
109
110
|
const tagName = el.nodeName.toLowerCase();
|
|
110
111
|
|
|
111
112
|
if (el.parentNode) {
|
|
112
|
-
const parentXPath = getElementXPath(el.parentNode
|
|
113
|
+
const parentXPath = getElementXPath(el.parentNode);
|
|
113
114
|
return `${parentXPath}/${tagName}[${index}]`;
|
|
114
115
|
}
|
|
115
116
|
|
|
@@ -120,9 +121,8 @@ function generateXPaths(node: Node | null): string[] {
|
|
|
120
121
|
if (!node) return [];
|
|
121
122
|
|
|
122
123
|
const xPath = getElementXPath(node);
|
|
123
|
-
const fullXPath = getElementXPath(node, true);
|
|
124
124
|
|
|
125
|
-
return [xPath
|
|
125
|
+
return [xPath];
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
export function getXpathsById(id: string): string[] | null {
|