Morgan
11 years agoFrequent Contributor
Incrementing an action
I'm trying to create a little script that loops through a dropdown to find the desired value. Can someone direct me as to an example? Thanks, Morgan
Initial code looks as follows.... what's not working is that the [Down] needs to increment each time. So first time, one down action is needed, second 2, etc...
Thanks!
Morgan
----
repeat // If X appears in the list, we select it and continue.
grdAnalyte.Keys(' ');
grdAnalyte.Keys('[Down][Enter]');
Delay(Std_Wait);
until frmAnalyte.Window('TDBGridInplaceEdit', '', 1).text = 'X';
until frmAnalyte.Window('TDBGridInplaceEdit', '', 1).text = 'X';
Is this a custom control similar to a Win32 ComboBox? If so, I would think that if you instantiate a variable of that type, then that would expose the item count for the dropdown similar to the method in the TestComplete Working with dropdowns support article:
procedure Main();
var
p, w, ComboBox: OleVariant;
begin
// Run Notepad
Win32API.WinExec('notepad.exe', SW_SHOWNORMAL);
// Obtain a combo box object
p := Sys.Process('NOTEPAD');
Sys.Keys('~of');
w := Sys.Process('NOTEPAD').Window('#32770', 'Font', 1);
ComboBox := w.Window('ComboBox', '', 5);
// Post the total number of items to the log
Log.Message('The total number of items:' + aqConvert.IntToStr(ComboBox.wItemCount));
end;
you could put the call to [Down] in a loop and increment the times that loop is executed each time it is called.
in pseudo code:
maxLoop = 0
repeat // If X appears in the list, we select it and continue.
maxLoop++
grdAnalyte.Keys(' ');
for (i=0; i < maxLoop; i++) {
grdAnalyte.Keys('[Down][Enter]');
}
Delay(Std_Wait);
Hmmm... I think I get what you are saying but I'm having trouble converting it to DelphiScript. Any ideas?
Appreciate the help!
Morgan
Hi - I can't help with Delphi (sorry).
Here is something in JScript which might be helpful? I wasn't sure what you were trying to do - this just selects a desired drop down using Keys to find the one you want - I actually have trouble sometimes using ClickItem function so sometimes use the Keys function:
function selectDropDown(theDropDown, valueToSelect) {
Log.Message("About to select the value " + valueToSelect + " from the drop down");
Delay(2000);
Aliases.RefreshMappingInfo();
theDropDown.WaitProperty("Exists", true, 10000);
theDropDown.scrollIntoView(false);//the false is important!
var theList = theDropDown.wItemList;
Log.Message(theList);
var currentIndex = theDropDown.selectedIndex;
var indexToClick = findItemIndex(theList, valueToSelect, SEMI_COLON);
var clicksNeeded = indexToClick - currentIndex;
if (clicksNeeded == 0) {
return;
} else if (clicksNeeded > 0) {
for (var i = 0; i < clicksNeeded; i++) {
theDropDown.Keys("[Down]");
}
} else {
for (var i = 0; i < clicksNeeded; i++) {
theDropDown.Keys("[Up]");
}
}
var currentIndex = theDropDown.selectedIndex;
}