| 442 | } |
| 443 | } |
| 444 | function getAllElementsByXpath(xpath, contextNode, doc = document) { |
| 445 | contextNode = contextNode || doc; |
| 446 | const result = []; |
| 447 | try { |
| 448 | const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); |
| 449 | for (let i = 0; i < query.snapshotLength; i++) { |
| 450 | const node = query.snapshotItem(i); |
| 451 | // 如果是 Element 节点 |
| 452 | if (node.nodeType === 1) result.push(node); |
| 453 | } |
| 454 | } catch (err) { |
| 455 | throw new Error(`无效 Xpath: ${xpath}`); |
| 456 | } |
| 457 | return result; |
| 458 | } |
| 459 | function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) { |
| 460 | if (!selector) return []; |
| 461 | contextNode = contextNode || doc; |