diff --git a/ElectronJS/main.js b/ElectronJS/main.js index 2f8bd41..4b530d2 100644 --- a/ElectronJS/main.js +++ b/ElectronJS/main.js @@ -787,7 +787,41 @@ async function beginInvoke(msg, ws) { let waitTime = parameters.waitTime; let element = await driver.findElement(By.tagName("body")); if (codeMode == 0) { - await execute_js(code, element, waitTime); + let result = await execute_js(code, element, waitTime); + let level = "success"; + if (result == -1) { + level = "info"; + } + if (result != null) { + notify_browser( + "JavaScript操作返回结果:" + result, + "JavaScript operation returns result: " + result, + level + ); + } + } else if (codeMode == 2) { // 循环内的JS代码 + let parent_node = JSON.parse(msg.message.parentNode); + let parent_xpath = parent_node.parameters.xpath; + if (parent_node.parameters.loopType == 2) { + parent_xpath = parent_node.parameters.pathList + .split("\n")[0] + .trim(); + } + let elementInfo = {iframe: parameters.iframe, xpath: parent_xpath, id: -1}; + let element = await findElementAcrossAllWindows( + elementInfo, notifyBrowser = false); //通过此函数找到元素并切换到对应的窗口 + let result = await execute_js(code, element, waitTime); + let level = "success"; + if (result == -1) { + level = "info"; + } + if (result != null) { + notify_browser( + "JavaScript操作返回结果:" + result, + "JavaScript operation returns result: " + result, + level + ); + } } else if (codeMode == 8) { //刷新页面 try { @@ -860,8 +894,8 @@ async function beginInvoke(msg, ws) { } else if (option == 11) { //单个提取数据参数 notify_browser( - "提示:提取数据操作只能试运行设置的JavaScript语句,且只针对第一个匹配的元素。", - "Hint: can only test JavaScript statement set in the data extraction operation, and only for the first matching element.", + "提示:提取数据字段的试运行操作只能测试设置的JavaScript语句,且只针对第一个匹配的元素。", + "Hint: can only test JavaScript statement set in the data extraction field operation, and only for the first matching element.", "info" ); let params = parameters.params; //所有的提取数据参数 @@ -885,6 +919,20 @@ async function beginInvoke(msg, ws) { ); if (element != null) { await execute_js(param.beforeJS, element, param.beforeJSWaitTime); + if(param.contentType == 9){ //针对元素的JavaScript代码返回值 + let result = await execute_js(param.JS, element); + let level = "success"; + if (result == -1) { + level = "info"; + } + if (result != null) { + notify_browser( + "JavaScript操作返回结果:" + result, + "JavaScript operation returns result: " + result, + level + ); + } + } await execute_js(param.afterJS, element, param.afterJSWaitTime); } } diff --git a/ElectronJS/src/taskGrid/FlowChart.html b/ElectronJS/src/taskGrid/FlowChart.html index a2fd891..333285b 100644 --- a/ElectronJS/src/taskGrid/FlowChart.html +++ b/ElectronJS/src/taskGrid/FlowChart.html @@ -243,6 +243,7 @@

+
Trail Run

Trail Run
diff --git a/ElectronJS/src/taskGrid/FlowChart.js b/ElectronJS/src/taskGrid/FlowChart.js index 19f83c9..cc6688b 100644 --- a/ElectronJS/src/taskGrid/FlowChart.js +++ b/ElectronJS/src/taskGrid/FlowChart.js @@ -175,7 +175,7 @@ let app = new Vue({ this.nowNode["title"] = LANG("运行操作系统命令", "Run OS Command"); break; case 2: - this.nowNode["title"] = LANG("执行JavaScript", "Run JavaScript"); + this.nowNode["title"] = LANG("循环内元素执行JS", "Run JS in Loop"); break; case 3: this.nowNode["title"] = LANG("退出循环", "Exit Loop"); @@ -505,7 +505,7 @@ function elementDblClick(e) { showInfo(LANG("试运行功能不适用于循环操作,请试运行循环内部的具体操作,如点击元素。", "The trial run function is not applicable to loop operations. Please try to run the specific operations in the loop, such as clicking elements.")); } } else { - if (nodeType == 5 && (app._data.nowNode["parameters"]["codeMode"] != 0 && app._data.nowNode["parameters"]["codeMode"] != 8)) { + if (nodeType == 5 && (app._data.nowNode["parameters"]["codeMode"] != 0 && app._data.nowNode["parameters"]["codeMode"] != 2 && app._data.nowNode["parameters"]["codeMode"] != 8)) { showInfo(LANG("试运行自定义操作功能只适用于执行JavaScript和刷新页面操作。", "The trial run custom action function is only applicable to run JavaScript and refresh page operations.")); } else { trailElement(app._data.nowNode, 1); diff --git a/ElectronJS/src/taskGrid/FlowChart_CN.html b/ElectronJS/src/taskGrid/FlowChart_CN.html index 0c93fa5..77832eb 100644 --- a/ElectronJS/src/taskGrid/FlowChart_CN.html +++ b/ElectronJS/src/taskGrid/FlowChart_CN.html @@ -243,6 +243,7 @@

+
试运行

试运行
diff --git a/ElectronJS/src/taskGrid/taskList.html b/ElectronJS/src/taskGrid/taskList.html index 3ec6461..f56554e 100644 --- a/ElectronJS/src/taskGrid/taskList.html +++ b/ElectronJS/src/taskGrid/taskList.html @@ -167,7 +167,7 @@ }, modifyTask: function (index, row) { let id = row.id; - let url = row.url; + let url = row.links.split("\n")[0]; console.log(index, row) let message = { //显示flowchart type: 1, //消息类型,传递链接 diff --git a/ElectronJS/tasks/315.json b/ElectronJS/tasks/315.json new file mode 100644 index 0000000..03d180c --- /dev/null +++ b/ElectronJS/tasks/315.json @@ -0,0 +1 @@ +{"id":315,"name":"京东全球版-专业的综合网上购物商城","url":"https://www.jd.com","links":"https://www.jd.com","create_time":"2023-12-29 22:34:23","update_time":"2023-12-29 22:38:36","version":"0.6.0","saveThreshold":10,"quitWaitTime":60,"environment":0,"maximizeWindow":0,"maxViewLength":15,"recordLog":1,"outputFormat":"xlsx","saveName":"current_time","dataWriteMode":1,"inputExcel":"","startFromExit":0,"pauseKey":"p","containJudge":false,"browser":"chrome","removeDuplicate":0,"desc":"https://www.jd.com","inputParameters":[{"id":0,"name":"urlList_0","nodeId":1,"nodeName":"打开网页","value":"https://www.jd.com","desc":"要采集的网址列表,多行以\\n分开","type":"text","exampleValue":"https://www.jd.com"}],"outputParameters":[{"id":0,"name":"Text","desc":"自定义操作返回的数据","type":"text","recordASField":1,"exampleValue":""},{"id":1,"name":"Link","desc":"自定义操作返回的数据","type":"text","recordASField":1,"exampleValue":""}],"graph":[{"index":0,"id":0,"parentId":0,"type":-1,"option":0,"title":"root","sequence":[1,2],"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0},"isInLoop":false},{"id":1,"index":1,"parentId":0,"type":0,"option":1,"title":"打开网页","sequence":[],"isInLoop":false,"position":0,"parameters":{"useLoop":false,"xpath":"","wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"url":"https://www.jd.com","links":"https://www.jd.com","maxWaitTime":10,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"cookies":""}},{"id":2,"index":2,"parentId":0,"type":1,"option":8,"title":"循环点击每个元素","sequence":[4,5,3],"isInLoop":false,"position":1,"parameters":{"history":4,"tabIndex":-1,"useLoop":false,"xpath":"/html/body/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div/a","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"loopType":1,"pathList":"","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0,"allXPaths":""}},{"id":5,"index":3,"parentId":2,"type":0,"option":2,"title":"点击元素","sequence":[],"isInLoop":true,"position":2,"parameters":{"history":4,"tabIndex":-1,"useLoop":true,"xpath":"","iframe":false,"wait":2,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":1,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":""}},{"id":3,"index":4,"parentId":2,"type":0,"option":5,"title":"Text","sequence":[],"isInLoop":true,"position":0,"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":0,"codeMode":2,"code":"return arguments[0].innerText","waitTime":0,"recordASField":1,"paraType":"text","emailConfig":{"host":"","port":465,"username":"","password":"","from":"","to":"","subject":"","content":""}}},{"id":4,"index":5,"parentId":2,"type":0,"option":5,"title":"Link","sequence":[],"isInLoop":true,"position":1,"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":1,"codeMode":2,"code":"return arguments[0].href","waitTime":0,"recordASField":1,"paraType":"text","emailConfig":{"host":"","port":465,"username":"","password":"","from":"","to":"","subject":"","content":""}}}]} \ No newline at end of file diff --git a/ExecuteStage/.vscode/launch.json b/ExecuteStage/.vscode/launch.json index 1cccb34..f237b43 100644 --- a/ExecuteStage/.vscode/launch.json +++ b/ExecuteStage/.vscode/launch.json @@ -12,7 +12,7 @@ "justMyCode": false, // "args": ["--ids", "[7]", "--read_type", "remote", "--headless", "0"] // "args": ["--ids", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"] - "args": ["--ids", "[67]", "--headless", "0", "--user_data", "0", "--keyboard", "0", + "args": ["--ids", "[13]", "--headless", "0", "--user_data", "0", "--keyboard", "0", "--read_type", "remote"] // "args": "--ids '[97]' --user_data 1 --server_address http://localhost:8074 --config_folder '/Users/naibo/Documents/EasySpider/ElectronJS/' --headless 0 --read_type remote --config_file_name config.json --saved_file_name" }