@midscene/recorder 0.23.5-beta-20250728070606.0 → 0.24.1-beta-20250728094050.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.
- package/dist/recorder-iife.js +43 -31
- package/package.json +2 -2
package/dist/recorder-iife.js
CHANGED
|
@@ -521,6 +521,7 @@
|
|
|
521
521
|
getNodeFromCacheList: ()=>getNodeFromCacheList,
|
|
522
522
|
getNodeInfoByXpath: ()=>getNodeInfoByXpath,
|
|
523
523
|
getXpathsById: ()=>getXpathsById,
|
|
524
|
+
getXpathsByPoint: ()=>getXpathsByPoint,
|
|
524
525
|
isNotContainerElement: ()=>isNotContainerElement,
|
|
525
526
|
setNodeHashCacheListOnWindow: ()=>setNodeHashCacheListOnWindow,
|
|
526
527
|
traverseTree: ()=>traverseTree,
|
|
@@ -1244,30 +1245,18 @@ ${indentStr}${after}`;
|
|
|
1244
1245
|
}
|
|
1245
1246
|
return index;
|
|
1246
1247
|
};
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
current = current.previousSibling;
|
|
1253
|
-
}
|
|
1254
|
-
return index;
|
|
1255
|
-
};
|
|
1256
|
-
var createNormalizeSpaceCondition = (textContent)=>`[normalize-space()="${textContent}"]`;
|
|
1257
|
-
var addTextContentToXPath = (el, baseXPath)=>{
|
|
1258
|
-
const textContent = el.textContent?.trim();
|
|
1259
|
-
if (textContent && (isButtonElement(el) || isFormElement(el))) return `${baseXPath}${createNormalizeSpaceCondition(textContent)}`;
|
|
1260
|
-
return baseXPath;
|
|
1261
|
-
};
|
|
1262
|
-
var getElementXPath = (element)=>{
|
|
1248
|
+
function normalizeText(text) {
|
|
1249
|
+
if ("string" != typeof text) return "";
|
|
1250
|
+
return text.replace(/\s+/g, " ").trim();
|
|
1251
|
+
}
|
|
1252
|
+
var getElementXPath = (element, isOrderSensitive, isLeafElement)=>{
|
|
1263
1253
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
1264
1254
|
const parentNode = element.parentNode;
|
|
1265
1255
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
1266
|
-
const
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
return `${parentXPath2}/text()[${textIndex}]`;
|
|
1256
|
+
const parentXPath = getElementXPath(parentNode, true);
|
|
1257
|
+
const textContent2 = element.textContent?.trim();
|
|
1258
|
+
if (textContent2) return `${parentXPath}/text()[normalize-space()="${normalizeText(textContent2)}"]`;
|
|
1259
|
+
return `${parentXPath}/text()`;
|
|
1271
1260
|
}
|
|
1272
1261
|
return "";
|
|
1273
1262
|
}
|
|
@@ -1277,19 +1266,37 @@ ${indentStr}${after}`;
|
|
|
1277
1266
|
if (el === document.body) return "/html/body";
|
|
1278
1267
|
const isSVG = "http://www.w3.org/2000/svg" === el.namespaceURI;
|
|
1279
1268
|
const tagName = el.nodeName.toLowerCase();
|
|
1280
|
-
if (isSVG
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1269
|
+
if (isSVG) {
|
|
1270
|
+
let parent = el.parentNode;
|
|
1271
|
+
while(parent && parent.nodeType === Node.ELEMENT_NODE){
|
|
1272
|
+
const parentEl = parent;
|
|
1273
|
+
if ("http://www.w3.org/2000/svg" !== parentEl.namespaceURI) return getElementXPath(parent, isOrderSensitive, isLeafElement);
|
|
1274
|
+
parent = parent.parentNode;
|
|
1275
|
+
}
|
|
1276
|
+
return getElementXPath(el.parentNode, isOrderSensitive, isLeafElement);
|
|
1284
1277
|
}
|
|
1285
|
-
const
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1288
|
-
|
|
1278
|
+
const textContent = el.textContent?.trim();
|
|
1279
|
+
const buildParentPath = ()=>{
|
|
1280
|
+
if (!el.parentNode) return "";
|
|
1281
|
+
return getElementXPath(el.parentNode, true);
|
|
1282
|
+
};
|
|
1283
|
+
const buildCurrentElement = (useIndex, useText)=>{
|
|
1284
|
+
const parentPath = buildParentPath();
|
|
1285
|
+
const prefix = parentPath ? `${parentPath}/` : "/";
|
|
1286
|
+
if (useText && textContent) return `${prefix}${tagName}[normalize-space()="${normalizeText(textContent)}"]`;
|
|
1287
|
+
if (useIndex) {
|
|
1288
|
+
const index = getElementIndex(el);
|
|
1289
|
+
return `${prefix}${tagName}[${index}]`;
|
|
1290
|
+
}
|
|
1291
|
+
return `${prefix}${tagName}`;
|
|
1292
|
+
};
|
|
1293
|
+
if (isOrderSensitive) return buildCurrentElement(true);
|
|
1294
|
+
if (isLeafElement) return buildCurrentElement(false, true);
|
|
1295
|
+
return buildCurrentElement(true);
|
|
1289
1296
|
};
|
|
1290
|
-
function generateXPaths(node) {
|
|
1297
|
+
function generateXPaths(node, isOrderSensitive) {
|
|
1291
1298
|
if (!node) return [];
|
|
1292
|
-
const fullXPath = getElementXPath(node);
|
|
1299
|
+
const fullXPath = getElementXPath(node, isOrderSensitive, true);
|
|
1293
1300
|
return [
|
|
1294
1301
|
fullXPath
|
|
1295
1302
|
];
|
|
@@ -1299,6 +1306,11 @@ ${indentStr}${after}`;
|
|
|
1299
1306
|
if (!node) return null;
|
|
1300
1307
|
return generateXPaths(node);
|
|
1301
1308
|
}
|
|
1309
|
+
function getXpathsByPoint(point, isOrderSensitive) {
|
|
1310
|
+
const element = document.elementFromPoint(point.left, point.top);
|
|
1311
|
+
if (!element) return null;
|
|
1312
|
+
return generateXPaths(element, isOrderSensitive);
|
|
1313
|
+
}
|
|
1302
1314
|
function getNodeInfoByXpath(xpath) {
|
|
1303
1315
|
const xpathResult = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
1304
1316
|
if (1 !== xpathResult.snapshotLength) return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/recorder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1-beta-20250728094050.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"antd": "^5.21.6",
|
|
25
25
|
"dayjs": "^1.11.11",
|
|
26
26
|
"react-dom": "18.3.1",
|
|
27
|
-
"@midscene/shared": "0.
|
|
27
|
+
"@midscene/shared": "0.24.1-beta-20250728094050.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "18.3.1",
|