Chrome是否使用XPath 2.0?

Ian*_*hek 16 selenium xpath google-chrome selenium-chromedriver

我的印象是所有最新的浏览器现在都使用XPath 2.当我使用lower-case()uppser-case()(版本2中引入的功能)时,Chrome会抛出语法错误.然而,他们较旧的替代品translate()工作正常.

这是一个错误还是最新的Chrome实际上使用XPath 1?是否有命令/方法来找出XPath版本?

// Finds the element as expected.
$x('//h2/text()[. = "Delete"]') 

// Doesn't find the element (also expected).
$x('//h2/text()[. = "delete"]') 

// SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//h2/text()[lower-case(.) = "delete"]' is not a valid XPath expression.
$x('//h2/text()[lower-case(.) = "delete"]')
Run Code Online (Sandbox Code Playgroud)

kjh*_*hes 18

不,Chrome使用XPath 1.0.

您可以将XPath表达式简化为v2.0函数以查看:

$x("lower-case('ABC')")
SyntaxError: Failed to execute 'evaluate' on 'Document': The string 'lower-case('ABC')' is not a valid XPath expression.
Run Code Online (Sandbox Code Playgroud)

尝试任何其他XPath 2.0函数current-date()会产生类似的错误.

除了这些探测之外,没有内置的方法可以明确地确定XPath实现的版本.

另一方面,XSLT system-property('xsl:version')用于确定版本1.0与2.0.

  • 2020 年 5 月,您好,Covid-19 封锁!Chrome 81 仍然不支持。 (9认同)
  • 2019年8月Chrome 76仍然如此 (3认同)
  • 答案向您展示了如何检查,但是,是的,2017 年 Chrome v55 仍然如此:仅支持 XPath 1.0,不支持 XPath 2.0。 (2认同)
  • 2018 年 11 月仍然如此 (2认同)
  • 这太糟糕了。为什么这仍然不支持?我将不得不编写丑陋的 xpath 代码来执行简单的区分大小写的搜索。编辑:显然,这永远不会被支持 https://github.com/whatwg/dom/issues/903#issuecomment-707748069 (2认同)

Hil*_*lle 9

谷歌Chrome(或Chromium)仍然使用libxml2,因此仅限于XPath 1.0.参看 本来自源代码的自述文件.