mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-12 03:27:08 +08:00
Fix bug: when cannot find elements, switch back to the original handle instead of one of the first two handles
This commit is contained in:
parent
9efd3b6efe
commit
2cf33794f1
@ -245,6 +245,7 @@ async function findElementAcrossAllWindows(
|
|||||||
let handles = await driver.getAllWindowHandles();
|
let handles = await driver.getAllWindowHandles();
|
||||||
// console.log("handles", handles);
|
// console.log("handles", handles);
|
||||||
let content_handle = current_handle;
|
let content_handle = current_handle;
|
||||||
|
let old_handle = current_handle;
|
||||||
let id = -1;
|
let id = -1;
|
||||||
try {
|
try {
|
||||||
id = msg.message.id;
|
id = msg.message.id;
|
||||||
@ -310,7 +311,7 @@ async function findElementAcrossAllWindows(
|
|||||||
if (h != null && handles.includes(h)) {
|
if (h != null && handles.includes(h)) {
|
||||||
await driver.switchTo().window(h);
|
await driver.switchTo().window(h);
|
||||||
current_handle = h;
|
current_handle = h;
|
||||||
console.log("switch to handle: ", h);
|
console.log("Switch to handle: ", h);
|
||||||
}
|
}
|
||||||
element = await findElement(driver, By.xpath, xpath, iframe);
|
element = await findElement(driver, By.xpath, xpath, iframe);
|
||||||
break;
|
break;
|
||||||
@ -327,6 +328,12 @@ async function findElementAcrossAllWindows(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element == null && notifyBrowser) {
|
if (element == null && notifyBrowser) {
|
||||||
|
// 如果找不到元素,切换回原来的窗口
|
||||||
|
if (old_handle != null && handles.includes(old_handle)) {
|
||||||
|
await driver.switchTo().window(old_handle);
|
||||||
|
current_handle = old_handle;
|
||||||
|
console.log("Switch to handle: ", old_handle);
|
||||||
|
}
|
||||||
notify_browser(
|
notify_browser(
|
||||||
"无法找到元素,请检查XPath是否正确:" + xpath,
|
"无法找到元素,请检查XPath是否正确:" + xpath,
|
||||||
"Cannot find the element, please check if the XPath is correct: " + xpath,
|
"Cannot find the element, please check if the XPath is correct: " + xpath,
|
||||||
|
1
ElectronJS/tasks/326.json
Normal file
1
ElectronJS/tasks/326.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user