I have a warning pop up that appears at random on my windows application(this warning is necessary) which needs associated hardware to fix the issue related with warning. This will not let the application work until its closed.
Anyway, my problem is when I am running another script, verifying something on the application, I need a way to look out for this dialog and close it while the script is running. Are there any ways/methods/keywords to do this?
Like I said, this warning happens at random so I cannot put the logic for it in one place in the script and expect it to work nor I can put it on every line. Any ideas on how to handle this? TIA
Please refer VBScript to detect an open messagebox and close it
Another solution
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.Linq;
namespace HandleDynamicDialog
{
public class Program
{
[DllImport("user32.dll")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_CLOSE = 0xF060;
static void Main(string[] args)
{
if (args.Length == 2)
{
//Pass your dialog class and title as command line arguments from uft script.
string targetDialogClass = args[0];
string targetDialogTitle = args[1];
//Verify UFT is launched
bool uftVisible = IsUftVisible();
while (uftVisible)
{
//Close the warning dialog
CloseDialog(targetDialogClass, targetDialogTitle);
}
}
}
/// <summary>
/// Close dialog using API
/// </summary>
/// <param name="dialogClass"></param>
/// <param name="dialogTitle"></param>
public static void CloseDialog(string dialogClass, string dialogTitle)
{
try
{
int winHandle = FindWindow(dialogClass, dialogTitle);
if (winHandle > 0)
{
SendMessage(winHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
Thread.Sleep(5000);
}
catch (Exception exception)
{
//Exception
}
}
/// <summary>
/// Verify UFT is visible or not
/// </summary>
/// <returns></returns>
public static bool IsUftVisible()
{
return Process.GetProcesses().Any(p => p.MainWindowTitle.Contains("HP Unified Functional Testing"));
}
}
}
From UFT
Call HandleDynamicDialog("CalcFrame","Calculator")
Public Sub HandleDynamicDialog(ByVal dialogClass,ByVal dialogTitle)
Dim objShell
Dim strCommandLineString
Set objShell = CreateObject("Wscript.Shell")
strCommandLineString = "C:\HandleWarningDialog.exe " & dialogClass & " " & dialogTitle
SystemUtil.CloseProcessByName "HandleWarningDialog.exe"
objShell.Exec(strCommandLineString)
Set objShell = Nothing
End Sub