Api Windows c # window handler

1

I have an application that has two forms (username and password), and I would like to design an application that logs in that other application automatically.

I've done it with SendKeys and it works pretty well, the problem is that if the user moves the window, or clicks out another form, the data is obviously passed there.

I've been reading about what alternatives exist, the Windows API and controlling the window of the application process.

Could someone guide me by giving me an example of how it would be used?

    
asked by Georgia Fernández 10.11.2018 в 02:23
source

2 answers

0

For Windows automation, be it UWP (Universal Windows Platform Application) or the legendary Winforms Win32 (called Classic Windows Application) you can try WinAppDriver - Windows Application Driver

What is basically WinAppDriver? You can automate UI in the same way that is done for example in Selenium Driver . That is, by C # code in this case of your need, to be able to manipulate the UI of the target application.

See the example for notepad

// Launch Notepad
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
appCapabilities.SetCapability("appArguments", @"MyTestFile.txt");
appCapabilities.SetCapability("appWorkingDir", @"C:\MyTestFolder\");
NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);

// Use the session to control the app
NotepadSession.FindElementByClassName("Edit").SendKeys("This is some text");

There are several examples in the repo

How to locate the elements of the form? the Id? Idem to the inspector of the pages you have an Inspect.exe tool that comes in the Windows SDK

An example of how to find the name here

Links that can help or guide you

I hope it will help or guide you

    
answered by 10.11.2018 в 11:19
-1

System.Diagnostics.Process [] ieProcs = Process.GetProcessesByName ("fsx");         if (ieProcs.Length > 0)         {             foreach (System.Diagnostics.Process p in ieProcs)             {                 SwitchToThisWindow (p.Handle, true);                 p.Refresh ();                 break;             }         }

    
answered by 10.11.2018 в 10:52