April 12, 2010
QA Wizard Pro: XPath Introduction
imageSources = Window("Seapine").PerformXPathQuery("//img/@src")This script action will run the "//img/@src" XPath on the Seapine web page. The imageSources variable will then contain an array of strings--all of the "src" attribute values of the image elements. I can go further and verify properties of the image URLs. In this particular example, I verify that all of the images in the web page begin with "http://www.seapine.com".
numImageSources = ArraySize(imageSources, 1)
For i = 1 To numImageSources
urlStart = Mid(imageSources(i), 1, 22)
If urlStart <> "http://www.seapine.com" Then
Fail("Unexpected URL: " & imageSources(i))
NextBy using XPath, you can avoid writing code to find elements in a web page, letting QA Wizard Pro do the hard work. If you find yourself using QA Wizard Pro's ExtractHTMLToString and HTMLFindByID functions to parse a web page, consider using PerformXPathQuery instead. Learning XPath can take time, but it's time well spent. The resulting scripts will be more concise, readable, and maintainable.