XPath

XPath is used to navigate through elements and attributes in an XML document.

Since HTML is basically an XML document, XPath can be useful in developing an automation test, web crawler, and perhaps an advanced XML parsing application.

Example of XPath syntax:

//input[@type="hidden"]
this syntax will return all inputs of which type are "hidden"

//input[@type="hidden"][@name="input_name"]
this syntax will return all inputs of which type are "hidden" and have the name "input_name"

//tr[contains(.,"some texts")]/td[1][contains(.,"more detailed text")]
this syntax will return the first which contains "more detailed text" and this is the child of which contains "some texts" in any of its elements or attributes.

To learn more about XPath, w3school provides a very brief and to-the-point tutorial.

To play around with XPath, install Firebug and then enable "Console" and type $x(' -- xpath syntax -- '), it will return the XML parts which match the XPath query.
It's very handy and fun!

0 comments: (+add yours?)