From eb0bd17432fbd71b11c6e55d78d79ed508350d27 Mon Sep 17 00:00:00 2001
From: hk <hk123456.com>
Date: Thu, 09 Jan 2025 11:11:27 +0800
Subject: [PATCH] 百度打标签

---
 rpa/src/slib/actions.js |  176 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 153 insertions(+), 23 deletions(-)

diff --git a/rpa/src/slib/actions.js b/rpa/src/slib/actions.js
index 12f787f..6882f24 100644
--- a/rpa/src/slib/actions.js
+++ b/rpa/src/slib/actions.js
@@ -132,6 +132,62 @@
  * @param platform {number} : 平台 (百度,QQ浏览器)
  * @return {boolean} : 返回是否成功
  */
+// actions.prototype.searchByKeyword = function (keyword, platform) {
+//     let result = false;
+//     let startNum = 3; //重试次数
+//     //搜索内容
+//     logd('准备搜索');
+//     dynamicData.deviceLog(true, {log_detail: '准备搜索'});
+//     let schemesItem = datas.schemes.filter(item => item.platform === platform);
+//     let map = {"uri": schemesItem[0].scheme["search"] + keyword};
+//     let num = 0;
+//     search:
+//         while (num < startNum) {
+//             try {
+//                 let searchLayout = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
+//                 if (searchLayout) {
+//                     let editableTextSelector = clz("android.widget.EditText");
+//                     if (editableTextSelector) {
+//                         click(editableTextSelector);
+//                         logd('搜索框已点击');
+//                         editableTextSelector.clearText();
+//                         inputText(editableTextSelector, keyword);
+//                         logd('输入搜索内容:' + keyword);
+//                         let searchBtn = text("搜索").getOneNodeInfo(5000);
+//                         if (searchBtn.click()) {
+//                             logd('搜索已点击');
+//                             result = true;
+//                         }
+//                     } else {
+//                         let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000);
+//                         if (searchBox.click()) {
+//                             logd('搜索框已点击');
+//                             let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
+//                             if (searchLayout2) {
+//                                 let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000);
+//                                 editTextSelector2.clearText();
+//                                 inputText(editTextSelector2, keyword);
+//                                 logd('输入搜索内容:' + keyword);
+//                                 let searchBtn = text("搜索").getOneNodeInfo(5000);
+//                                 if (searchBtn.click()) {
+//                                     logd('搜索已点击');
+//                                     result = true;
+//                                 }
+//                             }
+//                         }
+//                     }
+
+//                 }
+//                 logd(JSON.stringify(map));
+//             } catch (e) {
+//                 logd('搜索失败:' + e);
+//                 actions.prototype.exceptionLog('搜索失败:' + e);
+//             }
+//             num++;
+//         }
+//     return result;
+// }
+
 actions.prototype.searchByKeyword = function (keyword, platform) {
     let result = false;
     let startNum = 3; //重试次数
@@ -141,32 +197,25 @@
     let schemesItem = datas.schemes.filter(item => item.platform === platform);
     let map = {"uri": schemesItem[0].scheme["search"] + keyword};
     let num = 0;
+
     search:
         while (num < startNum) {
             try {
-                let searchLayout = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
-                if (searchLayout) {
-                    let editableTextSelector = clz("android.widget.EditText");
-                    if (editableTextSelector) {
-                        click(editableTextSelector);
+                if (platform === 4) {
+
+                    let searchLayout = id("com.baidu.searchbox:id/baidu_searchbox").getOneNodeInfo(5000);
+                    if (searchLayout&&searchLayout.click()) {
+                        // if (editableTextSelector) {
+                        // click(editableTextSelector);
+                        // editableTextSelector.click()
+                        let editableTextSelector = clz("android.widget.EditText").pkg("com.baidu.searchbox").getOneNodeInfo(5000);
                         logd('搜索框已点击');
-                        editableTextSelector.clearText();
-                        inputText(editableTextSelector, keyword);
-                        logd('输入搜索内容:' + keyword);
-                        let searchBtn = text("搜索").getOneNodeInfo(5000);
-                        if (searchBtn.click()) {
-                            logd('搜索已点击');
-                            result = true;
-                        }
-                    } else {
-                        let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000);
-                        if (searchBox.click()) {
-                            logd('搜索框已点击');
-                            let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
-                            if (searchLayout2) {
-                                let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000);
-                                editTextSelector2.clearText();
-                                inputText(editTextSelector2, keyword);
+                        sleep(1000);
+                        // editableTextSelector.clearText();
+                        if (editableTextSelector) {
+                            // editableTextSelector.pasteText(keyword)
+                            if (imeInputText(null, keyword)) {
+
                                 logd('输入搜索内容:' + keyword);
                                 let searchBtn = text("搜索").getOneNodeInfo(5000);
                                 if (searchBtn.click()) {
@@ -175,9 +224,90 @@
                                 }
                             }
                         }
-                    }
 
+                    } else {
+                        logd('没有找找到搜索按钮,第二种搜索方式');
+                        let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").depth(14).drawingOrder(2).child().getOneNodeInfo(5000)
+                        // toast(JSON.stringify(searchLayout2));
+                        if (searchLayout2&&searchLayout2.click()) {
+                            let editableTextSelector = clz("android.widget.EditText").pkg("com.baidu.searchbox").getOneNodeInfo(5000);
+                            sleep(1000);
+                            if (editableTextSelector) {
+                                if (imeInputText(null, keyword)) {
+
+                                    let searchBtn = text("搜索").getOneNodeInfo(5000);
+                                    if (searchBtn.click()) {
+                                        logd('搜索已点击');
+                                        result = true;
+                                    }
+                                }
+                            }
+                        }else{
+                            logd('没有找到搜索按钮 ');
+                        }
+                    }
+                    // editableTextSelector.clearText();
+                    // imeInputText(editableTextSelector, keyword);
+                    // searchBtn.click();
+                    // }
+                    // } else {
+                    //     let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000);
+                    //     if (searchBox.click()) {
+                    //         logd('搜索框已点击');
+                    //         let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
+                    //         if (searchLayout2) {
+                    //             let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000);
+                    //             editTextSelector2.clearText();
+                    //             inputText(editTextSelector2, keyword);
+                    //             logd('输入搜索内容:' + keyword);
+                    //             let searchBtn = text("搜索").getOneNodeInfo(5000);
+                    //             if (searchBtn.click()) {
+                    //                 logd('搜索已点击');
+                    //                 result = true;
+                    //             }
+                    //         }
+                    //     }
+                } else if (platform === 5) {
+                    //qq浏览器
+                    let searchLayout = id("com.tencent.mtt:id/search_bar_tv_hotword").getOneNodeInfo(5000);
+                    if (searchLayout && searchLayout.click()) {
+                        //获取到 准备写入
+                        sleep(1000);
+                        let editableTextSelector = id("com.tencent.mtt:id/search_frame_input_bar").getOneNodeInfo(5000);//.pkg('com.tencent.mtt')
+                        // let editableTextSelector = clz("android.widget.EditText").pkg("com.tencent.mtt").getOneNodeInfo(3000)
+                        logd(JSON.stringify(editableTextSelector));
+                        sleep(1000);
+                        if (editableTextSelector) {
+                            // imeInputText(editableTextSelector,keyword)
+                            // imeInputText(null,keyword)
+                            if (imeInputText(null, keyword)) {
+                                sleep(3000);
+                                let searchBtn = text("搜索").getOneNodeInfo(5000);
+                                if (searchBtn.click()) {
+                                    logd('搜索已点击');
+                                    result = true;
+                                }
+                            } else {
+                                logd('imeInputText 失败');
+
+                            }
+
+                            // pasteText(editableTextSelector, keyword)
+                            // editableTextSelector.inputText(keyword)
+
+                            // if (searchBtn.click()) {
+                            //     logd('搜索已点击');
+                            //     result = true;
+                            // }
+                        } else {
+                            logd('没有找到要写入的搜索框');
+                        }
+                    } else {
+                        logd('没有找到搜索框')
+                    }
                 }
+
+                // }
                 logd(JSON.stringify(map));
             } catch (e) {
                 logd('搜索失败:' + e);

--
Gitblit v1.9.3