autox.js 实现遍历微信聊天列表 并发送固定消息

1 怎么找到界面上的聊天item?

每个item左边都有一张图片,通过获取图片并判断图片的位置来确定是否是聊天item。

关键代码:

js 复制代码
 var iconList = className("android.widget.ImageView").find();
  
 for(var i =0;i<iconList.length;i++){
        var icon = iconList[i];

        var icon = iconList[i];
        var iconBottom = icon.bounds().bottom;
        var iconHeight = icon.bounds().height;
        var right = icon.bounds().right;

        if(right > deviceWidth / 4){
            continue;
           }
   
        if(iconBottom < topHeight || iconHeight < 50){
           continue;
        }

        if((icon.parent() != null && icon.parent().className() == "android.widget.RelativeLayout" )
        && (icon.parent().parent() != null && icon.parent().parent().className() == "android.widget.LinearLayout" )
        && (icon.parent().parent().parent() != null &&  icon.parent().parent().parent().className() == "android.widget.LinearLayout" )
        && (icon.parent().parent().parent().parent() != null && icon.parent().parent().parent().parent().className() == "android.widget.ListView" )
        ){
            var item = icon.parent().parent().parent();
            var itemWidth = item.bounds().width();
            var itemHeight = item.bounds().height();
            if(itemWidth < device.width * 0.9)continue;
            activeItemList.push(item)
        }
    }

2 怎么滑动保证不会多滑动或者少滑动

通过swipe操作,swipe操作可以指定滑动距离。

js 复制代码
 for(var i =0;i<activeItemList.length;i++){
    
            var item = activeItemList[i];
            var itemWidth = item.bounds().width();
            var itemHeight = item.bounds().height();
            var itemBototom = item.bounds().bottom;
            if(itemWidth < 900)continue;
            var eachItemHeight = itemHeight;
        
            item.click();
            console.log("=======itemClick====");
       
            openChatAndSend()
            sleep(200);
            console.log("=======itemBack");
            checkIsMainPage();
            var scrollHeight  = eachItemHeight;
            if(isFirstScroll){
                isFirstScroll = false;
                scrollHeight = itemBototom - topHeight;
            }
        
            swipe(device.width / 2, device.height / 2 , device.width / 2 , device.height/2 - scrollHeight, 100);
    
            if(maxIconBottom < item.bounds().bottom){
                maxIconBottom = item.bounds().bottom;
            }
    
           
        // }else {
        //     console.log("======jump333")
        // }
    }

3 怎么判断滑动到底部了。当滑动到底部的时候,最后一个item的Bottom是小于device.height的。可以用这个为依据。

js 复制代码
 if(maxIconBottom < device.height){
        isReachBottom = true
    }

4 怎么判断滑动到顶部?

这里取巧,只有滑动到顶部的时候plus_icon才能找到。

js 复制代码
function scrollToTop(listView){
    var topAddIcon = id("plus_icon").findOne(200);
    while(topAddIcon == null){
        listView.scrollBackward();
        topAddIcon = id("plus_icon").findOne(200);
    }
}

5 跳转到聊天界面,怎么输入文字。

找到输入框,然后settext

js 复制代码
    var enter = className("android.widget.EditText").findOne(400)

    if(enter == null){
        back()
        return;
    };
    enter.setText("😄")

6 怎么发送

js 复制代码
   var sendButton = className("android.widget.Button").text("发送").findOne(400);
//    if(sendButton != null){
//     sendButton.click()
//    }

7 怎么返回

这里一定要用Back() 不然会发现返回去之后,找不到聊天item了。

js 复制代码
back()

效果图:

相关推荐
Mr_sun.42 分钟前
Day09——入退管理-入住-2
android·java·开发语言
ujainu2 小时前
告别杂乱!Flutter + OpenHarmony 鸿蒙记事本的标签与分类管理(三)
android·flutter·openharmony
常利兵2 小时前
Android内存泄漏:成因剖析与高效排查实战指南
android
·云扬·2 小时前
MySQL 8.0 Redo Log 归档与禁用实战指南
android·数据库·mysql
野生技术架构师2 小时前
SQL语句性能优化分析及解决方案
android·sql·性能优化
doupoa4 小时前
内存指针是什么?为什么指针还要有偏移量?
android·c++
非凡ghost5 小时前
PowerDirector安卓版(威力导演安卓版)
android·windows·学习·软件需求
独行soc5 小时前
2026年渗透测试面试题总结-19(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
爱装代码的小瓶子7 小时前
【C++与Linux基础】进程间通讯方式:匿名管道
android·c++·后端
兴趣使然HX7 小时前
Android绘帧流程解析
android