mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-16 16:26:56 +08:00
Code Online Debugging!!!
This commit is contained in:
parent
de547cac11
commit
b5e06903bd
Binary file not shown.
Binary file not shown.
@ -198,7 +198,7 @@ async function findElement(driver, by, value, iframe = false) {
|
||||
}
|
||||
}
|
||||
|
||||
async function findElementAcrossAllWindows(msg) {
|
||||
async function findElementAcrossAllWindows(msg, notifyBrowser=true) {
|
||||
let handles = await driver.getAllWindowHandles();
|
||||
// console.log("handles", handles);
|
||||
let content_handle = current_handle;
|
||||
@ -223,9 +223,9 @@ async function findElementAcrossAllWindows(msg) {
|
||||
} catch {
|
||||
iframe = msg.iframe;
|
||||
}
|
||||
if (iframe) {
|
||||
notify_browser("在IFrame中执行操作可能需要较长时间,请耐心等待。", "Executing operations in IFrame may take a long time, please wait patiently.", "info");
|
||||
}
|
||||
// if (iframe) {
|
||||
// notify_browser("在IFrame中执行操作可能需要较长时间,请耐心等待。", "Executing operations in IFrame may take a long time, please wait patiently.", "info");
|
||||
// }
|
||||
let xpath = "";
|
||||
try {
|
||||
xpath = msg.message.xpath;
|
||||
@ -257,7 +257,7 @@ async function findElementAcrossAllWindows(msg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element == null) {
|
||||
if (element == null && notifyBrowser) {
|
||||
notify_browser("无法找到元素,请检查xpath是否正确:" + xpath, "Cannot find the element, please check if the xpath is correct: " + xpath, "warning");
|
||||
}
|
||||
return element;
|
||||
@ -356,7 +356,8 @@ async function beginInvoke(msg, ws) {
|
||||
url = parent_node["parameters"]["textList"].split("\n")[0];
|
||||
}
|
||||
await driver.get(url);
|
||||
} else if (option == 2 || option == 7) { //点击事件
|
||||
}
|
||||
else if (option == 2 || option == 7) { //点击事件
|
||||
let elementInfo = {"iframe": parameters.iframe, "xpath": parameters.xpath, "id": -1};
|
||||
if (parameters.useLoop) {
|
||||
let parent_node = JSON.parse(msg.message.parentNode);
|
||||
@ -378,7 +379,39 @@ async function beginInvoke(msg, ws) {
|
||||
await new Promise(resolve => setTimeout(resolve, afterJSWaitTime));
|
||||
}
|
||||
send_message_to_browser(JSON.stringify({"type": "cancelSelection"}));
|
||||
} else if (option == 4) { //键盘输入事件
|
||||
}
|
||||
else if (option == 3) { //提取数据
|
||||
notify_browser("提示:提取数据操作只能试运行设置的JavaScript语句。", "Hint: can only test JavaScript statement set in the data extraction operation.", "info");
|
||||
let paras = parameters.paras; //所有的提取数据参数
|
||||
let not_found_xpaths = [];
|
||||
for (let i = 0; i < paras.length; i++) {
|
||||
let para = paras[i];
|
||||
let xpath = para.relativeXPath;
|
||||
if (para.relative) {
|
||||
let parent_node = JSON.parse(msg.message.parentNode);
|
||||
let parent_xpath = parent_node.parameters.xpath;
|
||||
xpath = parent_xpath + xpath;
|
||||
}
|
||||
let elementInfo = {"iframe": para.iframe, "xpath": xpath, "id": -1};
|
||||
let element = await findElementAcrossAllWindows(elementInfo, notifyBrowser=false);
|
||||
if (element != null) {
|
||||
if (para.beforeJS != "") {
|
||||
await driver.executeScript(para.beforeJS, element);
|
||||
await new Promise(resolve => setTimeout(resolve, para.beforeJSWaitTime));
|
||||
}
|
||||
if (para.afterJS != "") {
|
||||
await driver.executeScript(para.afterJS, element);
|
||||
await new Promise(resolve => setTimeout(resolve, para.afterJSWaitTime));
|
||||
}
|
||||
} else {
|
||||
not_found_xpaths.push(xpath);
|
||||
}
|
||||
}
|
||||
if (not_found_xpaths.length > 0) {
|
||||
notify_browser("无法找到以下元素,请检查xpath是否正确:" + not_found_xpaths.join("\n"), "Cannot find the element, please check if the xpath is correct: " + not_found_xpaths.join("\n"), "warning");
|
||||
}
|
||||
}
|
||||
else if (option == 4) { //键盘输入事件
|
||||
let elementInfo = {"iframe": parameters.iframe, "xpath": parameters.xpath, "id": -1};
|
||||
let value = node.parameters.value;
|
||||
if (node.parameters.useLoop) {
|
||||
@ -432,7 +465,18 @@ async function beginInvoke(msg, ws) {
|
||||
// Interacting with dropdown element based on optionMode
|
||||
switch (optionMode) {
|
||||
case 0: //切换到下一个选项
|
||||
let script = "var options = arguments[0].options;for (var i = 0; i < options.length; i++) {if (options[i].selected) {options[i].selected = false;if (i == options.length - 1) {options[0].selected = true;} else {options[i + 1].selected = true;}break;}}";
|
||||
let script = `var options = arguments[0].options;
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
if (options[i].selected) {
|
||||
options[i].selected = false;
|
||||
if (i == options.length - 1) {
|
||||
options[0].selected = true;
|
||||
} else {
|
||||
options[i + 1].selected = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}`;
|
||||
await driver.executeScript(script, element);
|
||||
break;
|
||||
case 1:
|
||||
@ -544,7 +588,7 @@ let wss = new WebSocket.Server({port: websocket_port});
|
||||
wss.on('connection', function (ws) {
|
||||
ws.on('message', async function (message, isBinary) {
|
||||
let msg = JSON.parse(message.toString());
|
||||
console.log("\n\nGET A MESSAGE: ", msg);
|
||||
// console.log("\n\nGET A MESSAGE: ", msg);
|
||||
// console.log(msg, msg.type, msg.message);
|
||||
if (msg.type == 0) {
|
||||
if (msg.message.id == 0) {
|
||||
@ -553,17 +597,17 @@ wss.on('connection', function (ws) {
|
||||
// socket_window = null;
|
||||
// console.log("socket_window closed");
|
||||
// });
|
||||
console.log("set socket_window")
|
||||
// console.log("set socket_window at time: ", new Date());
|
||||
} else if (msg.message.id == 1) {
|
||||
socket_start = ws;
|
||||
console.log("set socket_start")
|
||||
console.log("set socket_start at time: ", new Date());
|
||||
} else if (msg.message.id == 2) {
|
||||
socket_flowchart = ws;
|
||||
// socket_flowchart.on('close', function (event) {
|
||||
// socket_flowchart = null;
|
||||
// console.log("socket_flowchart closed");
|
||||
// });
|
||||
console.log("set socket_flowchart");
|
||||
console.log("set socket_flowchart at time: ", new Date());
|
||||
} else { //其他的ID是用来标识不同的浏览器标签页的
|
||||
await new Promise(resolve => setTimeout(resolve, 2300));
|
||||
let handles = await driver.getAllWindowHandles();
|
||||
@ -577,6 +621,15 @@ wss.on('connection', function (ws) {
|
||||
socket_flowchart.send(JSON.stringify({"type": "title", "data": {"title": msg.message.title}}));
|
||||
allWindowSockets.push(ws);
|
||||
allWindowScoketNames.push(msg.message.id);
|
||||
console.log("set socket for id: ", msg.message.id, " at time: ", new Date());
|
||||
ws.on('close', function (event) {
|
||||
let index = allWindowSockets.indexOf(ws);
|
||||
if (index > -1) {
|
||||
allWindowSockets.splice(index, 1);
|
||||
allWindowScoketNames.splice(index, 1);
|
||||
}
|
||||
console.log("socket for id: ", msg.message.id, " closed at time: ", new Date());
|
||||
});
|
||||
// console.log("handle_pairs: ", handle_pairs);
|
||||
}
|
||||
} else if (msg.type == 10) {
|
||||
@ -626,7 +679,7 @@ async function runBrowser(lang = "en", user_data_folder = '', mobile = false) {
|
||||
.setChromeOptions(options)
|
||||
.setChromeService(serviceBuilder)
|
||||
.build();
|
||||
await driver.manage().setTimeouts({implicit: 10000, pageLoad: 10000, script: 10000});
|
||||
await driver.manage().setTimeouts({implicit: 3, pageLoad: 10000, script: 10000});
|
||||
await driver.executeScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})");
|
||||
// await driver.executeScript("localStorage.clear();"); //重置参数数量
|
||||
const cdpConnection = await driver.createCDPConnection("page");
|
||||
|
@ -91,7 +91,7 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>Hint: Move the mouse to the smiley face to view the hint, <b>double-click</b> the option in the flowchart to try to run.</label>
|
||||
<label>Tip: Hover over the smiley face to view hints, <b>double-click</b> on an action in the flowchart to test run, <b>right-click</b> on an action to see more options.</label>
|
||||
<label>Option Name:</label>
|
||||
<input onkeydown="inputDelete(event)" class="form-control" v-model='list.nl[index.nowNodeIndex]["title"]'></input>
|
||||
</div>
|
||||
|
@ -386,7 +386,7 @@ function elementDblClick(e) {
|
||||
try {
|
||||
let nodeType = app._data.nowNode["option"]
|
||||
if (nodeType >= 8) {
|
||||
showInfo(LANG("试运行功能不适用于循环和条件分支操作。", "The trial run function is not applicable to loop and condition branch operations."))
|
||||
showInfo(LANG("试运行功能不适用于循环和条件分支操作,请试运行循环或条件分支内部的具体操作,如点击元素。", "The trial run function is not applicable to loop and condition branch operations. Please try to run the specific operations in the loop/condition branch, such as clicking elements."));
|
||||
} else {
|
||||
if(nodeType == 5 && app._data.nowNode["parameters"]["codeMode"] != 0){
|
||||
showInfo(LANG("试运行自定义操作功能只适用于执行JavaScript操作。", "The trial run custom action function is only applicable to run JavaScript operation."))
|
||||
|
@ -91,7 +91,7 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>提示:鼠标移到笑脸可查看提示,在流程图中<b>双击</b>选项可试运行。</label>
|
||||
<label>提示:鼠标移到笑脸可查看提示,在流程图中<b>双击</b>操作可试运行,<b>右键</b>点击操作查看更多选项。</label>
|
||||
<label>选项名称</span>:</label>
|
||||
<input onkeydown="inputDelete(event)" class="form-control" v-model='list.nl[index.nowNodeIndex]["title"]'></input>
|
||||
</div>
|
||||
|
File diff suppressed because one or more lines are too long
@ -229,7 +229,7 @@ function createNotification(text, type="info") {
|
||||
setInterval(function () {
|
||||
let notifications = document.getElementsByClassName("notification_of_easyspider");
|
||||
for (let i = 0; i < notifications.length; i++) {
|
||||
if (new Date().getTime() - parseInt(notifications[i].getAttribute("data-timestamp")) > 10000) {
|
||||
if (new Date().getTime() - parseInt(notifications[i].dataset.timestamp) > 10000) {
|
||||
if (notifications[i].parentNode === document.body) {
|
||||
document.body.removeChild(notifications[i]); // 避免移除已经不存在的元素
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user