Validate DataGridView by using getPageSource(), in windows Application


I am automating a client specific AddIn within Windows application [Excel, Outlook] ]in my project via Katalon 7.4.0. It has a DataGridView where all the user details would be displayed based on the search criteria.


  1. User inputs “Name” into search field
  2. Hits Enter
  3. DataGridView displays details of all the users whose name contains the one given in step 1

Now i need to validate whether the each result returned in the grid have the Name provided.

I have used Xpath to get the DataGridView’s elements, stored them in a list and then i used getAttribute(“Value.Value”) on each element to get the name and validated if its matching or not. Problem with this approach is, its time consuming.

When i google’ed about any other possible way, came across method getPageSource() by which we can get the source as a string and do the validations, which takes less time when compared to the Xpath way i mentioned.

Then I tried method getPageSource(), it is returning the string which has properties of the “DataGridView” but not the search results.

Can anyone please let me know if there is any other way i can deal with slowness issue??


Just for your information:

Do you mean that driver.findElementByXPath("//*[@AutomationId='135']") takes long to execute?
If so, this is because you traversing whole desktop tree,

The speed of XPath evaluation strongly depends on how the expression is written. If the expression requires full traversal over a large document tree, the evaluation would be slow.

As you know, a careless SQL statement easily slows down your system. You would refine your SQL stetement before blaming the SQL technology. Same lesson applies to XPath expression.

If you could write the XPath evaluation more efficient (the expression should require minimum volume of traversal over the tree), the evaluation would get drastically quicker. I would recommend you to try to write “efficient XPath expression”. For example, as suggests, the // syntax tends to be very inefficient.

As describes:

// is short for /descendant-or-self::node()/ . For example, //para is short for /descendant-or-self::node()/child::para and so will select any para element in the document (even a para element that is a document element will be selected by //para since the document element node is a child of the root node); div//para is short for div/descendant-or-self::node()/child::para and so will select all para descendants of div children.

Please note that any and all here costs slowness of XPath evaluation.

If your XPath expression uses //, try to avoid using //, and to measure the speed.

WiniumDriver implements varieties of findElementBy*() methods:

findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath,

The findElementByXPath is just one of them. If the “DataGrid” is identifiable by @id, then you can use findElementById() to find the DataGrid. The findElementById() would run quick. And then you can search the descendants inside the DataGrid using findEementByXPath() — this way you can reduce the volume of tree traversal.

Hi Kazurayam,

Thanks for the information.

Below is the way i am accessing elements

Step 1: Launch WinAppDriver.Exe
Step 2: In Katalon, Windows.findElement(findWindowsObject()) or Windows.getDriver().findElement(By.Xpath()) to find Windwsobject

The 2 are similar. No difference in term of processing speed.

Thank you! Your solution worked