Hello Hamed,
You could try to make first a click on the close button, then a close application and then a kill application. You could then make them all optional by changing the setting for "Continue on fail" to "true" for all the actions:

- close.png (14.11 KiB) Viewed 617 times
If you need code, then you could use the following snippet:
var Processes=Process.GetProcessesByName("notepad");
string ProcessName="";
var repo = KeepTryingToCloseAppRepository.Instance;
var CloseButton = repo.UntitledNotepad.Close;
if (Processes.Length!=0)
{
ProcessName=Processes[0].ProcessName;
Report.Info(string.Format("Found {0} processees of application {1}. Attempting to close one with x button."
,Processes.Length.ToString(), ProcessName));
CloseButton.Click();
}
else if(Processes.Length==0)
{
Report.Info(string.Format("All processes of application {0} closed.", ProcessName));
}
Delay.Seconds(5);
Processes=Process.GetProcessesByName("notepad");
if (Processes.Length!=0)
{
Report.Info(string.Format("Found {0} processees of application {1}. Attempting to close one with Host.Current.CloseApplication()."
,Processes.Length.ToString(), ProcessName));
Host.Current.CloseApplication(repo.UntitledNotepad.Self,new Duration(0));
}
else if(Processes.Length==0)
{
Report.Info(string.Format("All processes of application {0} closed.", ProcessName));
}
Delay.Seconds(5);
Processes=Process.GetProcessesByName("notepad");
if (Processes.Length!=0)
{
Report.Info(string.Format("Found {0} processees of application {1}. Attempting to close the rest with KillProcess()."
,Processes.Length.ToString(), ProcessName));
foreach (Process _proces in Processes)
{
_proces.Kill();
}
}
else if(Processes.Length==0)
{
Report.Info(string.Format("All processes of application {0} closed."
, ProcessName));
}
Delay.Seconds(5);
Processes=Process.GetProcessesByName("notepad");
if (Processes.Length!=0)
{
Report.Info(string.Format("Found {0} processees of application {1}. Failed to kill processes."
,Processes.Length.ToString(), ProcessName));
Host.Current.CloseApplication(repo.UntitledNotepad.Self,new Duration(0));
}
else if(Processes.Length==0)
{
Report.Info(string.Format("All processes of application {0} closed.", ProcessName));
}
}
Don't forget to add the using directive "using System.Diagnostics;".
This is for closing notepad. The RanoreXPath to the close button should be
/form[@title~'Notepad']/?/?/button[@accessiblename='Close']. Note that I used a regex for the form, else the button might not be found if multiple instances are open. You can open like 10 notepad instances in order to test the code.
Let me know if it helps.
Regard,
McTurtle