Hi, I have provided
@ENRICO ROMEO the solution for this. I'm sharing it here.
Just change the
testing variables to the appropriate values for you (my OS was in Spanish).
The main script is
get_table_from_listview_control.wal.
I've broken down the problem into 3 parts:
launch_or_attach_msinfo32.walResponsible to launch the msinfo32 application.
defVar --name window --type Window --outputdefVar --name processId --type Numeric --outputdefVar --name success --type BooleanwaitWindow --useregex --regexPattern "\"Información del sistema\"|\"System Information\"" --regexOptions "IgnoreCase" --recursive --safesearch --timeout "00:00:02" --comment "remember: always use \'Safe Search\'" window=value processId=processId success=successif --left "${success}" --operator "Is_True" --negate launchWindow --executablepath "msinfo32.exe" --safesearch --timeout "00:00:04" --comment "remember: always use \'Safe Search\'" window=value processId=processId success=successendIfassert --message "Could not find system info window" --left "${success}" --operator "Is_True"focusWindow --window ${window}get_table_from_listview_control.walResponsible to get the table from any
ListView control. It works for the msinfo32.exe application or any other application that has this control. It also handles empty tables.
defVar --name value --type StringdefVar --name lastControl --type ControldefVar --name lastControlIndex --type NumericdefVar --name columnIndex --type NumericdefVar --name table --type DataTable --outputdefVar --name currentControl --type ControldefVar --name rowIndex --type NumericdefVar --name totalColumns --type NumericdefVar --name values --type List --innertype StringdefVar --name scriptsFolder --type StringdefVar --name treePath --type StringdefVar --name treeControlXPath --type StringdefVar --name window --type WindowdefVar --name errorOnIfCommand --type Boolean#region testing datasetVar --name "${scriptsFolder}" --value "C:\\Users\\JobertoDinizJunior\\Downloads"setVar --name "${treeControlXPath}" --value "/root/tree[1]"setVar --name "${treePath}" --value "Recursos de hardware/DMA"#endregionexecuteScript --isfromfile --filename "${scriptsFolder}\\launch_or_attach_msinfo32.wal" --output "window=${window}" --comment "launches or attaches the \'msinfo.exe\'"attachWindow --window ${window}executeScript --isfromfile --filename "${scriptsFolder}\\expand_SysTreeView32.wal" --parameters "scriptsFolder=${scriptsFolder},treePath=${treePath},controlXPath=${treeControlXPath},window=${window},interval=2000" --comment "expands the tree view as the \'expandTree\' command is not working for this tree"goSub --label BuildColumns --comment "build the table columns dynamically"goSub --label BuildRows --comment "build the table rows dynamically"logMessage --message "${table}" --type "Info"beginSub --name BuildColumns getControl --selector "XPath" --forcerefresh --xpath "/root/list[1]/header[1]/headeritem[last()]" lastControl=control assert --message "Could not find last control of the header" --left "${lastControl}" --operator "Is_Null" --negate evaluate --expression "${lastControl.Index} + 1" --comment "xpath indexes start at \'1\' and the control.index starts at \'0\'" lastControlIndex=value for --variable ${columnIndex} --from ${lastControlIndex} --to 1 --step -1 getControl --selector "XPath" --xpath "/root/list[1]/header[1]/headeritem[${columnIndex}]" currentControl=control addColumn --dataTable ${table} --columnname "${currentControl.InnerText}" --type String incrementVar --number ${totalColumns} --comment "unfortunately, \'table\' does not have \'Columns\' property =(" nextendSubbeginSub --name BuildRows onError --label ErrorOnGetControl getControl --selector "XPath" --xpath "/root/list[1]/listitem[last()]" lastControl=control if --left "${lastControl}" --operator "Is_Null" --negate --comment "only read rows if the \'lastControl\' exists. If it does not exist, it might mean the table is empty, and therefore no exception should be thrown" #region REMOVE THIS WHEN THE BUG IS FIXED if --left "${errorOnIfCommand}" --operator "Is_True" return endIf #endregion evaluate --expression "${lastControl.Index} + 1" --comment "xpath indexes start at \'1\' and the control.index starts at \'0\'" lastControlIndex=value for --variable ${rowIndex} --from ${lastControlIndex} --to 1 --step -1 --comment "loop each row" for --variable ${columnIndex} --from ${totalColumns} --to 1 --step -1 --comment "loop each column (cell)" getValue --selector "XPath" --xpath "/root/list[1]/listitem[${rowIndex}]/text[${columnIndex}]" value=value add --collection "${values}" --value "${value}" next addRow --valueset ${values} --dataTable ${table} clear --collection "${values}" next endIfendSubbeginSub --name ErrorOnGetControl//This code should be really simple, however there is a BUG in the 'if' command that throws an error when checking for NULL in the 'lastControl' variable #region ENABLE THIS WHEN THE BUG IS FIXED//setVar --name "${lastControl}" --comment "when an error occurs in the \'BuildRows\', assign NULL to the \'lastControl\' and let the code continue."//recover #endregion #region REMOVE THIS WHEN THE BUG IS FIXED case --switches "CaseSwitchesAll" when --left "${wdg:error.Command}" --operator "Equal_To" --right if when --left "${wdg:error.Message}" --operator "Begins_With" --right "Object reference" then setVar --name "${errorOnIfCommand}" --value true otherwise setVar --name "${lastControl}" endCase recover #endregionendSubexpand_SysTreeView32.walThis is not required for the problem, but I have created another generic script that expands the
TreeView of any application similar to msinfo32.exe. The expandTree command is not working with this tree, but this script will.
defVar --name controlXPath --type String --parameterdefVar --name scriptsFolder --type String --parameterdefVar --name treePath --type String --parameterdefVar --name interval --type TimeSpan --parameterdefVar --name nodes --type List --innertype StringdefVar --name node --type StringdefVar --name window --type Window --parameter#region testingsetVarIf --variablename "${scriptsFolder}" --value "C:\\Users\\JobertoDinizJunior\\Downloads" --left "${scriptsFolder}" --operator "Is_Null_Or_Empty"setVarIf --variablename "${interval}" --value "00:00:02" --left "${interval}" --operator "Equal_To" --right 0setVarIf --variablename "${controlXPath}" --value "/root/tree[1]" --left "${controlXPath}" --operator "Is_Null_Or_Empty"setVarIf --variablename "${treePath}" --value "Recursos de hardware/DMA" --left "${treePath}" --operator "Is_Null_Or_Empty"if --left "${window}" --operator "Is_Null" executeScript --isfromfile --filename "${scriptsFolder}\\launch_or_attach_msinfo32.wal" --output "window=${window}"endIf#endregionattachWindow --window ${window}splitString --text "${treePath}" --delimiteroption "CustomDelimiter" --customdelimiter "/" nodes=valueforeach --collection "${nodes}" --variable "${node}" click --selector "Name" --doubleclick --controlsimilarity 100 --forcerefresh --name "${node}" delay --timeout "${interval}"endFor------------------------------
Joba Diniz
Product Manager
IBM
------------------------------
Original Message:
Sent: Fri January 07, 2022 04:55 AM
From: ENRICO ROMEO
Subject: Get the "ListViewItem" number from a "List Box"
Hello,
Thanks for your quick reply. I tried the "GetOptions" command many times using different selectors but I get always the same error "Could not find Test Control for Control Type list item and FrameWorkId:Win32 .
Using the Get Value command I can get the value from a ListView Item (the first row of the list for example, the OS name: Microsoft Windows 10 Enterprise).
(Xpath used for the selector is: /root/list[1]/listitem[41]/text[1] )
What would you do?
Thanks
------------------------------
ENRICO ROMEO
Original Message:
Sent: Tue January 04, 2022 06:58 AM
From: Joba Diniz
Subject: Get the "ListViewItem" number from a "List Box"
The getOptions command returns a datatable with the data you need, then you just count the rows of the table.
------------------------------
Joba Diniz
Product Manager
IBM
Original Message:
Sent: Tue December 28, 2021 04:59 AM
From: ENRICO ROMEO
Subject: Get the "ListViewItem" number from a "List Box"
Hello everyone!
I would like to take the number of the ListView Items from a ListBox (class name SysListView32). Some Windows applications has a "table" like the picture below (msinfo32.exe). I have used the recorder in order to take the Xpath from the ListBox. I still can't find any commands in order to get the number of rows from this screen element (List box '202'), in this case I have 40 ListView Items:
------------------------------
-------------------
ENRICO ROMEO
-------------------
------------------------------