172 lines
5.9 KiB
TypeScript
172 lines
5.9 KiB
TypeScript
import { WDAHelper } from '../utils/wda-helper';
|
||
|
||
async function main() {
|
||
console.log('=== 探索Bot Settings页面内容 ===\n');
|
||
|
||
const wda = new WDAHelper();
|
||
await wda.createSession();
|
||
|
||
try {
|
||
// 1. 找Bot 0F
|
||
console.log('1. 查找Bot 0F...');
|
||
let botCard = await wda.findBotCard();
|
||
if (!botCard) {
|
||
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;
|
||
}
|
||
console.log(' ✓ 找到Bot 0F');
|
||
|
||
// 2. 点击Bot卡片
|
||
console.log('2. 点击Bot 0F...');
|
||
await wda.tapElement(botCard);
|
||
await new Promise(r => setTimeout(r, 1500));
|
||
|
||
// 3. 找并点击Settings
|
||
console.log('3. 查找Settings...');
|
||
const settingsId = await wda.findElement('name', 'Settings');
|
||
if (!settingsId) {
|
||
// 弹框可能消失了,重试
|
||
console.log(' 未找到Settings,重新点击Bot...');
|
||
botCard = await wda.findBotCard();
|
||
if (botCard) {
|
||
await wda.tapElement(botCard);
|
||
await new Promise(r => setTimeout(r, 1000));
|
||
const retry = await wda.findElement('name', 'Settings');
|
||
if (retry) {
|
||
await wda.tapElement(retry);
|
||
await new Promise(r => setTimeout(r, 3000));
|
||
} else {
|
||
console.log(' ✗ 仍未找到Settings');
|
||
await wda.destroySession();
|
||
return;
|
||
}
|
||
}
|
||
} else {
|
||
console.log(' ✓ 点击Settings');
|
||
await wda.tapElement(settingsId);
|
||
await new Promise(r => setTimeout(r, 3000));
|
||
}
|
||
|
||
// 4. 获取设置页完整source并分析
|
||
console.log('\n4. 分析设置页内容...\n');
|
||
const source = await wda.getSource();
|
||
|
||
// 找所有Cell元素(不限visible)
|
||
const cellRegex = /<XCUIElementTypeCell[^>]*>/g;
|
||
let match;
|
||
const cells: string[] = [];
|
||
while ((match = cellRegex.exec(source)) !== null) {
|
||
cells.push(match[0]);
|
||
}
|
||
console.log(` Cell元素总数: ${cells.length}`);
|
||
cells.forEach((c, i) => {
|
||
const name = c.match(/name="([^"]*)"/)?.[1] || '';
|
||
const visible = c.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if (name) console.log(` [${i}] name="${name}" visible=${visible}`);
|
||
});
|
||
|
||
// 找所有StaticText
|
||
const textRegex = /<XCUIElementTypeStaticText[^>]*>/g;
|
||
const texts: string[] = [];
|
||
while ((match = textRegex.exec(source)) !== null) {
|
||
texts.push(match[0]);
|
||
}
|
||
console.log(`\n StaticText元素总数: ${texts.length}`);
|
||
texts.forEach((t, i) => {
|
||
const name = t.match(/name="([^"]*)"/)?.[1] || '';
|
||
const value = t.match(/value="([^"]*)"/)?.[1] || '';
|
||
const label = t.match(/label="([^"]*)"/)?.[1] || '';
|
||
const visible = t.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if ((name || value || label) && visible === 'true') {
|
||
console.log(` [${i}] name="${name}" value="${value}" label="${label}"`);
|
||
}
|
||
});
|
||
|
||
// 找所有Button
|
||
const btnRegex = /<XCUIElementTypeButton[^>]*>/g;
|
||
const btns: string[] = [];
|
||
while ((match = btnRegex.exec(source)) !== null) {
|
||
btns.push(match[0]);
|
||
}
|
||
console.log(`\n Button元素总数: ${btns.length}`);
|
||
btns.forEach((b, i) => {
|
||
const name = b.match(/name="([^"]*)"/)?.[1] || '';
|
||
const visible = b.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if (name && visible === 'true') {
|
||
console.log(` [${i}] name="${name}"`);
|
||
}
|
||
});
|
||
|
||
// 找所有Switch
|
||
const switchRegex = /<XCUIElementTypeSwitch[^>]*>/g;
|
||
const switches: string[] = [];
|
||
while ((match = switchRegex.exec(source)) !== null) {
|
||
switches.push(match[0]);
|
||
}
|
||
if (switches.length > 0) {
|
||
console.log(`\n Switch元素总数: ${switches.length}`);
|
||
switches.forEach((s, i) => {
|
||
const name = s.match(/name="([^"]*)"/)?.[1] || '';
|
||
const value = s.match(/value="([^"]*)"/)?.[1] || '';
|
||
const visible = s.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if (visible === 'true') console.log(` [${i}] name="${name}" value="${value}"`);
|
||
});
|
||
}
|
||
|
||
// 5. 滚动后再看
|
||
console.log('\n5. 滚动后内容...');
|
||
await wda.scrollDown(400);
|
||
await new Promise(r => setTimeout(r, 2000));
|
||
|
||
const source2 = await wda.getSource();
|
||
const textRegex2 = /<XCUIElementTypeStaticText[^>]*>/g;
|
||
const texts2: string[] = [];
|
||
while ((match = textRegex2.exec(source2)) !== null) {
|
||
texts2.push(match[0]);
|
||
}
|
||
console.log(` 滚动后StaticText (visible=true):`);
|
||
texts2.forEach((t, i) => {
|
||
const name = t.match(/name="([^"]*)"/)?.[1] || '';
|
||
const value = t.match(/value="([^"]*)"/)?.[1] || '';
|
||
const label = t.match(/label="([^"]*)"/)?.[1] || '';
|
||
const visible = t.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if ((name || value || label) && visible === 'true') {
|
||
console.log(` [${i}] name="${name}" value="${value}" label="${label}"`);
|
||
}
|
||
});
|
||
|
||
// 再滚动
|
||
await wda.scrollDown(400);
|
||
await new Promise(r => setTimeout(r, 2000));
|
||
const source3 = await wda.getSource();
|
||
const textRegex3 = /<XCUIElementTypeStaticText[^>]*>/g;
|
||
const texts3: string[] = [];
|
||
while ((match = textRegex3.exec(source3)) !== null) {
|
||
texts3.push(match[0]);
|
||
}
|
||
console.log(`\n 再滚动后StaticText (visible=true):`);
|
||
texts3.forEach((t, i) => {
|
||
const name = t.match(/name="([^"]*)"/)?.[1] || '';
|
||
const value = t.match(/value="([^"]*)"/)?.[1] || '';
|
||
const label = t.match(/label="([^"]*)"/)?.[1] || '';
|
||
const visible = t.match(/visible="([^"]*)"/)?.[1] || '';
|
||
if ((name || value || label) && visible === 'true') {
|
||
console.log(` [${i}] name="${name}" value="${value}" label="${label}"`);
|
||
}
|
||
});
|
||
|
||
} catch (error: any) {
|
||
console.error('失败:', error.message);
|
||
}
|
||
await wda.destroySession();
|
||
console.log('\n=== 完成 ===');
|
||
}
|
||
|
||
main();
|