How to launch application and Press on the button on that window
- Launch the App
- Loop through Process
- Get the process Name Based on our Application Name. Basically this get's the process on your desktop/start bar
- If found the same, Get the Window Handle, process.MainWindowHandle
- After having the Handle, use the WinAPI
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetWindowRect(IntPtr hwnd, out Diversity.Web.Test.WebUIUnitTest.Rect lpRect);
- Create a Struct To hold it.
- [StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int Left{get;set;}
public int Top{get;set;}
public int Right { get; set; }
public int Bottom { get; set; }
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public static bool operator ==(Rect first, Rect second)
{
return ((first.Left == second.Left) && (first.Right == second.Right) && (first.Top == second.Top) && (first.Bottom == second.Bottom));
}
public static bool operator !=(Rect first, Rect second)
{
return !(first == second);
}
}
- Use the Function and Passed in the Handle, NativeMethods.GetWindowRect(hWnd, out rct);
- Use the Library i found earlier, which has mouse simulator, click the x and y that you want to, but please measure the distance first
You might also want to Maximize the Window first and click using the settoforeground API