in reply to Some issues with WWW::Mechanize::Firefox->xpath() method

FWIW, if you fireup firefox web console with ctrl+shift+k and execute

document.evaluate( 'substring(//title,1,9)', document , null , XPathRe +sult.ANY_TYPE , null )
you will get a [object XPathResult], and if you click on it, there will be a stringValue: "Comment o"

So you need Dump-er earlier and pick the right key/attribute

Found by grep for xpath in mechanize-firefox/mozrepl, lookup https://developer.mozilla.org/en-US/docs/DOM/document.evaluate and https://developer.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript

  • Comment on Re: Some issues with WWW::Mechanize::Firefox->xpath() method (ctrl+shift+k, stringValue)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Some issues with WWW::Mechanize::Firefox->xpath() method (ctrl+shift+k, stringValue)
by Corion (Patriarch) on Apr 02, 2013 at 12:39 UTC

    Ah hah!

    The difference in behaviour is caused by WWW::Mechanize::Firefox / MozRepl::RemoteObject using XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, while your code uses XPathResult.ANY_TYPE. I'm not certain about whether ANY_TYPE will guarantee an ordered snapshot, which I consider important, as I'd like the nodes to appear in "document order" in the result, and I'd like them to remain unchanged from the time the snapshot was taken, because there is transfer latency between Firefox and Perl.

    The documentation talks about nodes, so it seems that there is no way to get an ordered snapshot with strings...

    I don't see an easy way to automatically determine the "natural" result type of an expression, so in the middle term, MozRepl::RemoteObject::Methods::xpath needs to also take the result type as an (optional) parameter. Then, the Firefox ->xpath API can be extended to allow specifying the kind of result.

      The documentation talks about nodes, so it seems that there is no way to get an ordered snapshot with strings...

      If this could help, from previous running C++ code dealing directly with the XPCom layer, we found that, while using the ANY_TYPE:

      • The resulting elements have always been returned (as expected) in the document order (aka a depth first tree walk).
      • Even if not predictable at the query time, the exact result type, is driven by the expression query elements (btw, it would be nice to have it returned, to prevent recomputing it from query analysis).

      ____
      HTH, Dominique
      My two favorites:
      If the only tool you have is a hammer, you will see every problem as a nail. --Abraham Maslow
      Bien faire, et le faire savoir...