AI_UIAutomation/scripts/probe-pc7.ts

9 lines
794 B
TypeScript

import { createDriver } from '../drivers/factory';
const sleep=(ms:number)=>new Promise(r=>setTimeout(r,ms));
const dump=async(d:any):Promise<string[]>=>[...new Set((Array.from((await d.getSource()).matchAll(/text="([^"]+)"/g)) as any[]).map(m=>m[1]).filter((t:string)=>t.trim()&&t.length<40))] as string[];
(async()=>{const d=createDriver();await d.createSession();try{
const s=await d.findElementRaw('-android uiautomator','new UiSelector().text("Save")').catch(()=>null);
if(s){await d.tapElement(s);await sleep(4000);await d.dismissPopupIfPresent();await sleep(1500);console.log('点Save后: '+JSON.stringify(await dump(d)));}
else console.log('无Save, 当前: '+JSON.stringify(await dump(d)));
}catch(e:any){console.error('FAIL:',e.message);}finally{await d.destroySession();}})();