Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Chrome use XPath 2.0?

Tags:

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"]') 
like image 806
Ian Bytchek Avatar asked Aug 22 '14 20:08

Ian Bytchek


People also ask

Does browser engine support XPath 2.0 functions like ends with?

XPath 2.0 is fully included as a subset in XQuery 1.0, so you will be able to use all XPath 2.0 features (and more) in all browsers with JavaScript support. Show activity on this post. Majority of the browsers do not support XPATH 2.0, please see Comparison of layout engines to get more information.

How can I tell if XPath is correct in Chrome?

You can open the DevTools in Chrome with CTRL+I on Windows (or CMD+I Mac), and Firefox with F12 , then select the Console tab), and check the XPath by typing $x("your_xpath_here") . This will return an array of matched values. If it is empty, you know there is no match on the page.

What is the easiest way to find XPath?

Go to the First name tab and right click >> Inspect. On inspecting the web element, it will show an input tag and attributes like class and id. Use the id and these attributes to construct XPath which, in turn, will locate the first name field.


1 Answers

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.

like image 50
kjhughes Avatar answered Sep 27 '22 22:09

kjhughes