Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

selenium - Does Chrome use XPath 2.0?

I was under impression that all latest browsers are with XPath 2 now. When I use lower-case() and uppser-case() (functions introduced in version 2) Chrome throws a syntax error. However, their older alternative translate() works fine.

Is this a bug or does the latest Chrome actually use XPath 1? Is there a command / way to find out the XPath version?

// 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"]')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No, Chrome uses XPath 1.0.

You can simplify your XPath expression to just a v2.0 function to see this:

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

Trying any other XPath 2.0 function such as current-date() will yield a similar error.

There is no built-in way of definitively determining the version of an XPath implementation other than by such probes.

XSLT, on the other hand, has system-property('xsl:version') for determining version 1.0 versus 2.0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

2.1m questions

2.1m answers

60 comments

56.8k users

...