- // 初始延迟10秒
- sleep(10000);
- // 循环次数设定为20次
- for (var loop = 0; loop < 99999999; loop++) {
- var lastElementX, lastElementY;
- // 获取所有TextView控件
- var allTextViews = className("android.widget.TextView").find();
- // 遍历所有TextView控件,判断是否在屏幕可见范围内且包含"已拼"
- for (var i = 0; i < allTextViews.length; i++) {
- var currentTextView = allTextViews[i];
- if (currentTextView.text().indexOf("已拼") !== -1 && isVisible(currentTextView)) {
- var bounds = currentTextView.bounds();
- console.log("找到可见的'已拼'元素: " + currentTextView.text());
- click(bounds.centerX(), bounds.centerY());
- sleep(1600);
- lastElementX = bounds.centerX();
- lastElementY = bounds.centerY();
- // 寻找并点击包含'店铺'的TextView
- var shopTextView = text("店铺").visibleToUser().findOne(1000);
- if (shopTextView != null) {
- var shopBounds = shopTextView.bounds();
- console.log("找到'店铺'元素: " + shopTextView.text());
- click(shopBounds.centerX(), shopBounds.centerY());
- sleep(1600);
- // 寻找并点击包含'全部商品'的TextView
- var allProductsTextView = text("全部商品").visibleToUser().findOne(1000);
- if (allProductsTextView != null) {
- var allProductsBounds = allProductsTextView.bounds();
- console.log("找到'全部商品'元素: " + allProductsTextView.text());
- click(allProductsBounds.centerX(), allProductsBounds.centerY());
- sleep(1600);
- // 在这里加入新的代码
- //获取店名字
- function 获取所有控件的文本() {
- var 控件文本 = [];
- var 所有控件 = find();
- 所有控件.forEach(function(控件) {
- if(控件.text()) {
- 控件文本.push(控件.text());
- }
- });
- return 控件文本;
- }
- var 控件文本 = 获取所有控件的文本();
- console.log("所有控件的文本: ", 控件文本);
- var 最终变量="所有控件的文本:"+控件文本
- var originalText =最终变量
-
- var originalText =最终变量
- // 先移除 "所有控件的文本:" 部分
- var contentText = originalText.replace("所有控件的文本:", "");
- // 使用逗号分割内容
- var items = contentText.split(',');
- // 根据是否包含关键字“满”选择提取的文本
- var extractedText;
- if (items[0].includes("满") && items.length > 1) {
- extractedText = items[1]; // 如果第一个元素包含“满”且存在第二个元素,则选择第二个元素
- } else {
- extractedText = items[0]; // 否则,选择第一个元素
- }
- console.log(extractedText);
- setClip(extractedText);
- // 要追加的内容
- var contentToAdd = extractedText
- // 文件路径
- var filePath = "/storage/emulated/0/拼多多/pd.txt";
- // 打开文件,准备追加内容
- var file = open(filePath, "a"); // 'a' 模式表示追加(append)
- // 检查文件是否成功打开
- if (file) {
- // 向文件追加内容,并添加换行符
- file.writeline(contentToAdd);
- // 关闭文件
- file.close();
- } else {
- // 文件打开失败的处理
- console.log("无法打开文件:" + filePath);
- }
- back()
- sleep(1600);
- back()
- sleep(1600);
- //获取店名字
- // 这里加入新的代码结束
- } else {
- console.log("未找到'全部商品'元素");
- }
- // 寻找并点击描述为'分享'的控件
- var shareDesc = id("pdd").className("android.widget.ImageView").desc("分享").findOne(1000);
-
- } else {
- console.log("未找到'店铺'元素");
- }
- } else {
- console.log("元素不可见或不包含'已拼': " + currentTextView.text());
- }
- }
- // 从保存的坐标滑动到屏幕顶部
- if (lastElementX !== undefined && lastElementY !== undefined) {
- sleep(1600);
- swipe(lastElementX, lastElementY-100, lastElementX, 0, 1600);
- sleep(1600);
- } else {
- // swipe(device.width / 2, device.height / 2, device.width / 2, 0, 1600);
- sleep(1600);
- }
- }
- // 隐藏控制台
- setTimeout(function() {
- console.hide();
- }, 5000);
- // 判断元素是否对用户可见
- function isVisible(element) {
- var bounds = element.bounds();
- var screenBounds = { left: 0, top: 0, right: device.width, bottom: device.height };
- return bounds.left < screenBounds.right && bounds.right > screenBounds.left &&
- bounds.top < screenBounds.bottom && bounds.bottom > screenBounds.top;
- }
复制代码 我用的是autojs pro8.0测试的 需要无障碍
|
上一篇:autojs检测判断是否开启无障碍,如果没开启就自动跳转开启下一篇:autojs怎么找控件更准确,分享一些我个人的经验
|