@nbakka/mcp-appium 1.0.27 → 1.0.28
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/lib/server.js +20 -17
package/package.json
CHANGED
package/src/lib/server.js
CHANGED
|
@@ -147,40 +147,43 @@ server.tool(
|
|
|
147
147
|
// Get visible text elements including duplicates
|
|
148
148
|
server.tool(
|
|
149
149
|
"get_visible_text_elements",
|
|
150
|
-
"Get all visible texts from screen
|
|
150
|
+
"Get all visible texts from screen XML source including duplicates",
|
|
151
151
|
{},
|
|
152
152
|
async () => {
|
|
153
153
|
if (!state.sessionId) return { content: [{ type: "text", text: "No active session" }] };
|
|
154
154
|
try {
|
|
155
155
|
const response = await axios.get(`${APPIUM_URL}/session/${state.sessionId}/source`);
|
|
156
|
-
const
|
|
156
|
+
const xml = response.data;
|
|
157
157
|
console.log(response.data);
|
|
158
|
-
|
|
158
|
+
const parsed = await parseStringPromise(xml, { explicitArray: false, mergeAttrs: true });
|
|
159
|
+
|
|
160
|
+
function collectTextsFromXml(node, texts = []) {
|
|
159
161
|
if (!node) return texts;
|
|
162
|
+
|
|
163
|
+
// If array, recurse each element
|
|
160
164
|
if (Array.isArray(node)) {
|
|
161
|
-
node.forEach(child =>
|
|
165
|
+
node.forEach(child => collectTextsFromXml(child, texts));
|
|
162
166
|
return texts;
|
|
163
167
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
168
|
+
|
|
169
|
+
// If node has 'text' attribute with non-empty value, collect it
|
|
170
|
+
if (node.text && node.text.trim() !== "") {
|
|
171
|
+
texts.push(node.text.trim());
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Recurse into all children nodes
|
|
175
|
+
for (const key in node) {
|
|
176
|
+
if (key !== "text" && typeof node[key] === "object") {
|
|
177
|
+
collectTextsFromXml(node[key], texts);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
return texts;
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
const allTexts =
|
|
183
|
+
const allTexts = collectTextsFromXml(parsed);
|
|
181
184
|
return { content: [{ type: "json", json: allTexts }] };
|
|
182
185
|
} catch (e) {
|
|
183
|
-
return { content: [{ type: "text", text: `Error fetching or parsing source: ${e.message}` }] };
|
|
186
|
+
return { content: [{ type: "text", text: `Error fetching or parsing source XML: ${e.message}` }] };
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
);
|