(xpath, contextNode, doc = document)
| 1465 | |
| 1466 | |
| 1467 | function getXpath(xpath, contextNode, doc = document) { |
| 1468 | contextNode = contextNode || doc; |
| 1469 | try { |
| 1470 | const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
| 1471 | // 应该总是返回一个元素节点 |
| 1472 | return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; |
| 1473 | } catch (err) { |
| 1474 | throw new Error(`无效 Xpath: ${xpath}`); |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | // 显示问题作者 |
no outgoing calls
no test coverage detected