(xpath, contextNode, doc = document)
| 432 | return [].slice.call(contextNode.querySelectorAll(css)); |
| 433 | } |
| 434 | function getElementByXpath(xpath, contextNode, doc = document) { |
| 435 | contextNode = contextNode || doc; |
| 436 | try { |
| 437 | const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
| 438 | // 应该总是返回一个元素节点 |
| 439 | return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; |
| 440 | } catch (err) { |
| 441 | throw new Error(`Invalid xpath: ${xpath}`); |
| 442 | } |
| 443 | } |
| 444 | function getAllElementsByXpath(xpath, contextNode, doc = document) { |
| 445 | contextNode = contextNode || doc; |
| 446 | const result = []; |
no outgoing calls
no test coverage detected