PhantomJS 支持哪个 XPath 版本?

Which XPath version is supported in PhantomJS?

我将 Selenium 与 PhantomJS 结合使用。我如何找出 PhantomJS 中使用的 XPath 版本?

您可以直接查看是否支持特定功能。例如,boolean() is provided by XPath 1.0, but abs() 仅由 XPath 2.0 提供。

PhantomJS 1.x & 2.0 仅支持 XPath 1.0.

完整脚本:

var page = require('webpage').create();

console.log(JSON.stringify(page.evaluate(function(){
    var b = -1, body = -1, abs = -1;
    try{
        b = document.evaluate("boolean('a')", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
    }catch(e){}
    try{
        body = !!document.evaluate("//body", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }catch(e){}
    try{
        abs = document.evaluate("abs(-10.5)", document, null, XPathResult.NUMBER_TYPE, null).numberValue;
    }catch(e){}
    return {
        "boolean": b,
        "body": body,
        "abs(-10.5)": abs,
    };
}), undefined, 4));
phantom.exit();

输出:

{
    "abs(-10.5)": -1,
    "body": true,
    "boolean": true
}