google-chrome - Chrome 是否使用 XPath 2.0?

标签 google-chrome selenium xpath 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"]')

最佳答案

不,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.

尝试任何其他 XPath 2.0 功能,例如 current-date()会产生类似的错误。

除了通过此类探测之外,没有任何内置方法可以明确确定 XPath 实现的版本。

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

关于google-chrome - Chrome 是否使用 XPath 2.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25455351/

相关文章:

html - 用户代理样式表 - 不需要的边距和无覆盖工作

java - 使用 Java 使用 Selenium WebDriver 获取页面标题

xml - 为什么计数节点不起作用?

xslt - xsl 模板匹配忽略命名空间

java - 如何在 MVEL 表达式中使用 substring 字符串函数

javascript - 无法使用 Web OTP API 实现 OTP

jquery - Chrome 说没有 'Access-Control-Allow-Origin' header ,但 header 在那里

java - 错误: not found: java Usage: selenium-standalone action [options]

java - 导入org.openqa.selenium.firefox.FirefoxDriver无法解析

javascript - 这是与输入+数据列表相关的 Chrome UI 性能错误吗?