//跳转到聊天页面
app.startActivity({
action: "android.intent.action.VIEW",
data: "mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin=" + qq,
packageName: "com.tencent.mobileqq",
});
//打开个人主页
try{
app.startActivity({
action:"android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?&uin=" + Quin
});
}catch(e){
toast("Error");
}
起因就是QQ上要和朋友每天相互点赞,然后之前也没接触过脚本,就想了解一下,发现手机端主要就是auto.js,按键精灵,触动精灵,有JavaScript的基础,所以开始接触auto.js。
var Quin = ;//这里输入要点赞的好友QQ
//打开个人主页
try{
app.startActivity({
action:"android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?&uin=" + Quin
});
toast("嘎");//测试是否成功
}catch(e){
toast("Error");
}
sleep(2000);
//个人主页点赞
try{
//个人页面
var phoneButton1 = desc("音视频通话").findOne();
var dianzanButton = phoneButton1.parent().parent().parent().parent().parent().child(2).child(0).child(0).child(0).child(0).child(2).child(0).child(1);
//连点10下
for(var i = 0;i<10;i++){
dianzanButton.click();
}
toast("嘎嘎嘎");//测试是否成功
}catch(e){
toast("Error");
}
这里面主要是QQ的接口,刚开始不知道可以这样,一直在琢磨如何打开应用以后找到对应的好友,后来在网上发现了这个就方便多了。
其中个人页面里面在找点赞图标的组件的时候花了很长时间,一种方法是通过叠加属性来查找,在没有desc和id等明确属性的时候可用。
//选取控件属性depth值为3,控件属性drawingOrder值为0,控件属性indexInParent值为1的控件,查找一次;
var button = className("android.widget.EditText").depth(3).drawingOrder(0).indexInParent(0).findOne();
不过后来调试的时候老是不成功,后来用了一个较为繁琐的方法,找到一个不容易变化的或容易找的控件“.findone()”后再在此基础上进行“.parent()”“.child(index)”操作找到另一控件。如刚开始的例子中我用的就是通过找页面最下面有明确desc的一个组件,通过父级和子级的关系确定到点赞的组件。