Using XPath queries in statements

Some HTML elements in web applications may not be stored in the application repository if actions cannot be performed on them when recording, they are not recognized as controls, or they are dynamic. You can use an XPath query to identify these elements in statements so QA Wizard Pro can interact with them when running web scripts. For example, use an XPath query in a checkpoint to verify that the image path for an SRC attribute on a web page matches an expected value.

When adding XPath queries to statements, replace the control the action is performed on with the GetControlFromXPathQuery statement. You can also use the PerformXPathQuery statement to return an array of results that matches a specific XPath query. See GetControlFromXPathQuery and PerformXPathQuery.

Note: You can also use the XPath search method to identify HTML controls stored in the application repository if they are not located during playback. See Using the XPath search method.

1. Select the script line above where to add the statement.

2. Choose Script > Add Statement.

The Add Statement dialog box opens.

3. Select the statement to add.

4. The Application/version field is automatically set with the context. This information is used to populate the Window and Control fields on the Add Statement dialog box with values from the application repository. See Script.SetContext.

If QA Wizard Pro cannot identify the context, None is selected. This usually occurs when you add statements to a utility script that is only called by other scripts because the context is set in the script that calls it. If an application/version is required, select it from the list.

5. Select the Window that contains the element.

6. Select <XPath Query> as the Control.

7. Select the XPath Search Criteria.

Note: QA Wizard Pro automatically adds the GetControlFromXPathQuery statement based on the selected search criteria. For example, the following statement uses an XPath query to locate and click a button on the WysiCorp Home window:
Window("WysiCorp Home").Button(Window("WysiCorp Home").GetControlFromXPathQuery("html[1]/body[1]/table[2]/tbody")).Click()

8. Enter or select any additional statement information.

9. Click OK to add the statement to the script.