Flamingo.XPath.test()

The test() method returns TRUE if node specified by XPath exists on the current page and FALSE otherwise.

Syntax

Flamingo.XPath.test(xPath, parent)

Parameters

Parameter Type Description
xPath String XPath expression.
parent Node object Context node against which specified XPath will be executed.

Return Value

Type Description
Boolean TRUE if node is found by XPath or FALSE otherwise.

Example

The example below demonstrates how to check if H1 element exists on page.

Source HTML code available on your original desktop site page:

<html>
 <body>
   <h1>Hello World!</h1>
 </body>
</html>

You need to add the following code to your template to check if the H1 element exists on your page, return it or tell that it is not available:

<!--{if Flamingo.XPath.test('//h1') }-->
    Page title is: <!--{= Flamingo.XPath.value('//h1') }-->
<!--{else}-->
    There is no page title.
<!--{/if}-->

The result for sample source HTML will look like:

Page title is: Hello World!

See also