140 lines
4.6 KiB
TypeScript
140 lines
4.6 KiB
TypeScript
import { WDAHelper } from '../utils/wda-helper';
|
||
|
||
async function main() {
|
||
console.log('=== WDA精确操作:Bot 0F → Settings → 设置页 ===\n');
|
||
|
||
const wda = new WDAHelper();
|
||
await wda.createSession();
|
||
|
||
try {
|
||
// 找到Bot 0F卡片
|
||
console.log('1. 查找Bot 0F...');
|
||
let botCard = await wda.findBotCard();
|
||
|
||
if (!botCard) {
|
||
console.log(' 首页未找到,滚动...');
|
||
await wda.scrollDown(200);
|
||
await new Promise((r) => setTimeout(r, 2000));
|
||
botCard = await wda.findBotCard();
|
||
}
|
||
|
||
if (!botCard) {
|
||
console.log(' ✗ 找不到Bot 0F!');
|
||
await wda.destroySession();
|
||
return;
|
||
}
|
||
|
||
const rect = await wda.getElementRect(botCard);
|
||
console.log(` ✓ 找到Bot 0F: x=${rect.x}, y=${rect.y}, ${rect.width}x${rect.height}`);
|
||
|
||
// 点击Bot 0F卡片中心
|
||
console.log('\n2. 点击Bot 0F卡片中心...');
|
||
await wda.tapElement(botCard);
|
||
await new Promise((r) => setTimeout(r, 3000));
|
||
|
||
// 检查是否弹出了菜单(有Settings按钮)
|
||
console.log('\n3. 查找Settings按钮...');
|
||
const settingsId = await wda.findElement('name', 'Settings');
|
||
if (settingsId) {
|
||
const settingsRect = await wda.getElementRect(settingsId);
|
||
console.log(` ✓ Settings按钮: x=${settingsRect.x}, y=${settingsRect.y}, ${settingsRect.width}x${settingsRect.height}`);
|
||
|
||
// 也看看其他菜单选项
|
||
const source = await wda.getSource();
|
||
const buttons = source.match(/XCUIElementTypeButton[^>]*name="([^"]*)"[^>]*visible="true"/g);
|
||
if (buttons) {
|
||
console.log(' 当前可见按钮:');
|
||
buttons.forEach((b) => {
|
||
const name = b.match(/name="([^"]*)"/)?.[1];
|
||
if (name) console.log(` - ${name}`);
|
||
});
|
||
}
|
||
|
||
// 点击Settings
|
||
console.log('\n4. 点击Settings...');
|
||
await wda.tapElement(settingsId);
|
||
await new Promise((r) => setTimeout(r, 3000));
|
||
|
||
// 列出设置页所有元素
|
||
console.log('\n5. 设置页内容:');
|
||
const settingsSource = await wda.getSource();
|
||
|
||
// 找所有Cell(设置项)
|
||
const cells = settingsSource.match(/<XCUIElementTypeCell[^>]*name="([^"]*)"[^>]*visible="true"/g);
|
||
if (cells) {
|
||
console.log(' 设置项(Cell):');
|
||
cells.forEach((c) => {
|
||
const name = c.match(/name="([^"]*)"/)?.[1];
|
||
console.log(` - ${name}`);
|
||
});
|
||
}
|
||
|
||
// 找所有可见的StaticText
|
||
const texts = settingsSource.match(/<XCUIElementTypeStaticText[^>]*value="([^"]*)"[^>]*visible="true"/g);
|
||
if (texts) {
|
||
console.log(' 文字(StaticText):');
|
||
const uniqueTexts = new Set<string>();
|
||
texts.forEach((t) => {
|
||
const val = t.match(/value="([^"]*)"/)?.[1];
|
||
if (val && !uniqueTexts.has(val)) {
|
||
uniqueTexts.add(val);
|
||
console.log(` - ${val}`);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 滚动查看更多
|
||
console.log('\n6. 滚动设置页...');
|
||
await wda.scrollDown(300);
|
||
await new Promise((r) => setTimeout(r, 2000));
|
||
|
||
const settingsSource2 = await wda.getSource();
|
||
const cells2 = settingsSource2.match(/<XCUIElementTypeCell[^>]*name="([^"]*)"[^>]*visible="true"/g);
|
||
if (cells2) {
|
||
console.log(' 滚动后设置项:');
|
||
cells2.forEach((c) => {
|
||
const name = c.match(/name="([^"]*)"/)?.[1];
|
||
console.log(` - ${name}`);
|
||
});
|
||
}
|
||
|
||
const texts2 = settingsSource2.match(/<XCUIElementTypeStaticText[^>]*value="([^"]*)"[^>]*visible="true"/g);
|
||
if (texts2) {
|
||
console.log(' 文字:');
|
||
const uniqueTexts = new Set<string>();
|
||
texts2.forEach((t) => {
|
||
const val = t.match(/value="([^"]*)"/)?.[1];
|
||
if (val && !uniqueTexts.has(val)) {
|
||
uniqueTexts.add(val);
|
||
console.log(` - ${val}`);
|
||
}
|
||
});
|
||
}
|
||
|
||
} else {
|
||
console.log(' ✗ 未找到Settings按钮!');
|
||
// 列出当前所有可见元素
|
||
const source = await wda.getSource();
|
||
const allNames = source.match(/name="([^"]*)".*?visible="true"/g);
|
||
if (allNames) {
|
||
console.log(' 当前可见元素名称:');
|
||
const unique = new Set<string>();
|
||
allNames.slice(0, 20).forEach((m) => {
|
||
const name = m.match(/name="([^"]*)"/)?.[1];
|
||
if (name && !unique.has(name)) {
|
||
unique.add(name);
|
||
console.log(` - ${name}`);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
console.log('\n=== 完成 ===');
|
||
} catch (error: any) {
|
||
console.error('\n失败:', error.message);
|
||
}
|
||
await wda.destroySession();
|
||
}
|
||
|
||
main();
|