javavbscriptautomationhp-uft

Not able to get cell data from JavaTable


I have the table below and I am not being able to get its text, the one written 'Text to retrive".

Table from were I am trying to get the text

The code I am using is below, in this case it brings me a blank string:

Dim a
TableRows = WpfWindow("Window").JavaWindow("JFrame").JavaTable("JavaTable").GetROProperty("rows")
For Iterator = 0 To TableRows Step 1
a = WpfWindow("Window").JavaWindow("JFrame").JavaTable("JavaTable").getCellData(Iterator,1)
Next

I also tried with the code below but whithout success, in this case it gives me an error:

Dim a
TableRows = WpfWindow("Window").JavaWindow("JFrame").JavaTable("JavaTable").GetROProperty("rows")
For Iterator = 0 To TableRows Step 1
a = WpfWindow("Window").JavaWindow("JFrame").JavaTable("JavaTable").Object.getValueAt(Iterator,1)
Next

Solution

  • Is your table an awt or swt based table? (Lookup the toolkit class) IN case of swt, things can get complicated as UFT is relying mostly on the getText JavaMethod of a cell to get the value in it. In case the devs used JFace or some sophisticated rendering, you may need to sit down with them and ask for the proper way to read out the textual value of a cell from the memory.

    Most of the time you would have to use the .Object (Native Java) methods to get access to a TableItem Object and then you can try your lock with the getData.toString method, or other methods on the Object returned by getData(). ALthough storing complex data with set/get Data methods on a TableItem might be a common practice, it is not a rule. In some cases you may really need to sit down with a developer, or if not present reverse engieer / read the code yourself (Of course only if it's legally allowed)

    In Summary: You have to understand how the developers stored complex data in table items, and then teach UFT to be able to get the text from it whenever you need to. This implies the use of .Object(Native Java methods).

    Of course, if you do not wanna see this code in your test libraries you can think of an Extensibility Kit Solution with UFT Java Add-In ext.