Forum Discussion
Sorry, my example was not correct, please check the .ClickButton() methods :
function ProjectEvents_OnUnexpectedWindow(Sender, Window, LogParams) { Window.Activate(); myApp = Aliases.MyApp; var String1 = "The last "; var String2 = "Number of"; //..orders/days/items var String3 = "There are"; //..1/2/3/4/5/6..orders! or Validation failed! There are ....orders! switch(Window.MappedName) { case "Aliases.MyApp.frmMain": Log.Warning("MyApp was handled as 'Unexpected' window"); break; case "Aliases.MyApp.dlgApp": var message = myApp.dlgMyApp.Child(myApp.dlgMyApp.ChildCount - 1).Name; if(message.includes(String1)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),true); myApp.dlgMyApp.btnYes.ClickButton(); break; } else if(message.includes(String2)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),false); myApp.dlgMyApp.btnYes.ClickButton(); break; } else if(message.includes(String3)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),true); myApp.dlgMyApp.btnNO.ClickButton(); break; }
} else if(message.includes(String3)) {
DevLogMessage("The text of the popped up window: " + TrimMessage(message),true);
myApp.dlgMyApp.btnOK.ClickButton();
break;
}
}
As you can see, I have to handle them differently because each of them has different button as well... :(
Therefore your reorganized code would cause failure. Sorry for giving bad example.
Again, just checking... there are two "if" statements including String3... is that correct? And your brackets are off somewhere in there, too... so...
Without having accurate code, I can't give an accurate suggestion. But... thinking "out loud" here...
There might be a way of doing a logical check of the string once without having to check it 4 different times or there might be a methodology that is better, performance wide, than "includes".
Perhaps you could also create an array or matrix or dictionary of the three string segments and associated "parameters". Something like
"String1", "true", "btnYes"
"String2", "false", "btnYes"
"String3", "true, "btnNo"
And so on... then you can just call one routine that checks which row to reference and then utilize the expected parameters.
Related Content
- 2 years ago
Recent Discussions
- 2 days ago
- 2 days ago
- 5 days ago