【问题标题】:Which XPath version is supported in PhantomJS?PhantomJS 支持哪个 XPath 版本?
【发布时间】:2015-04-25 12:15:45
【问题描述】:

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

【问题讨论】:

    标签: selenium xpath phantomjs version ghostdriver


    【解决方案1】:

    您可以直接查看是否支持特定功能。例如,boolean() 由 XPath 1.0 提供,但 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-26
      • 2020-01-05
      • 2018-06-21
      • 2012-10-06
      • 2021-05-19
      • 2021-11-08
      • 2019-04-02
      • 2015-09-01
      相关资源
      最近更新 更多