UI Automation: How to set focus, click buttons, enter text programmatically

Find and share HowTos to various installations / configurations!
5 posts • Page 1 of 1
flindecke
Posts:69
Joined: Wed Jun 24, 2015 1:54 pm

UI Automation: How to set focus, click buttons, enter text programmatically

Post by flindecke »

I am currently try to find a bug in my software and it is easier to write an automated test for this case.

So i am searching for a way to automate ui interaction programatically, i.e. clicking on a button, enter text (like in .NET API https://msdn.microsoft.com/de-de/librar ... 10%29.aspx))

Does anybody know a solution?

With regards,
Frank Lindecke

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: UI Automation: How to set focus, click buttons, enter text programmatically

Post by kilianvp »

if you have the Version 3.15 with last Patch you can use the new setCursorPosition Function.

and use nircmd.exe to send a mouse click.

Code: Select all

void clickButton(shape button)
{
  dyn_int pos = button.positionAsDyn;
  dyn_int size = button.sizeAsDyn;
  int x = pos[1] + (size[1]/2);
  int y = pos[2] + (size[2]/2);
  setCursorPosition(x ,y);
  string sdtout;
  string sdterr;
  string sSystemCall = getPath(BIN_REL_PATH,"nircmd.exe");
      
  sSystemCall = sSystemCall + " sendmouse left click";
  system("cmd /c "+sSystemCall, sdtout, sdterr);
  delay(0,5);
}
  

and later you can do something like

Code: Select all

clickButton(getShape("PUSH_BUTTON1"));

flindecke
Posts:69
Joined: Wed Jun 24, 2015 1:54 pm

Re: UI Automation: How to set focus, click buttons, enter text programmatically

Post by flindecke »

@Kilian von Pflugk You made my day

Now i need to find out the global position of a panel on the screen and i am finished.

Thanks for your tip

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: UI Automation: How to set focus, click buttons, enter text programmatically

Post by kilianvp »

You can use

Code: Select all

int x, y; 
panelPosition("","",x,y);
thats the left upper corner of the panel

Image
Attachments
WCCOAui_2017_09_27_18_15_32.png

flindecke
Posts:69
Joined: Wed Jun 24, 2015 1:54 pm

Re: UI Automation: How to set focus, click buttons, enter text programmatically

Post by flindecke »

In the meanwhile i found this function and added an offset (due to window title etc.)
It works like a charm.

As already mentioned: You made my day

5 posts • Page 1 of 1