Herb191

Window resisting automation

6 posts in this topic

#1 ·  Posted (edited)

I have a window without a title in a program that is resisting automation. I can activate it, read its text with WinGetText and I can examine the controls using the Window Info tool but get no response when I use: ControlClick, ControlSetText, ControlSend, Send or _WinAPI_Keybd_Event. The below code returns 0 (window/control is not found). Any suggestions on how I can automate it without MouseClick?

$Winhandle = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.33c0d9d]", "")
WinActivate($Winhandle)
WinWaitActive($Winhandle)

$Error = ControlSetText($Winhandle, "", "[CLASS:WindowsForms10.EDIT.app.0.33c0d9d; INSTANCE:1]", "12345")

MsgBox(0, "", $Error)

From Window Tool:

>>>> Window <<<<
Title:  
Class:  WindowsForms10.Window.8.app.0.33c0d9d
Position:   543, 102
Size:   280, 564
Style:  0x16820000
ExStyle:    0x00010101
Handle: 0x003E0960

>>>> Control <<<<
Class:  WindowsForms10.EDIT.app.0.33c0d9d
Instance:   1
ClassnameNN:    WindowsForms10.EDIT.app.0.33c0d9d1
Name:
Edited by Herb191

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Do you also got an empty field in the windows process list ?

or even in task manager application list?

Edited by caramen

Share this post


Link to post
Share on other sites

Wich is the program you want automate ?

Share this post


Link to post
Share on other sites

see examples thread iuiautomation and try simplespy to see if you can read and see the controls. Basic sourcecode as given by simplespy shows how to setfocus to the editbox and you can change example then to type text into the control

 

I was able to get it to enter the data I need. Now all I need to to is invoke or click the OK control button. But for some reason I can't get it to work.

#RequireAdmin
#include "UIAWrappers.au3"

AutoItSetOption("MustDeclareVars", 1)

Local $oP1 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children)
Local $oP0 = _UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children)

_UIA_Action($oP0, "setfocus")
_UIA_setVar(".mainwindow", "title:=;classname:=WindowsForms10.EDIT.app.0.33c0d9d")
_UIA_setVar("OK.mainwindow", "title:=;classname:=WindowsForms10.Window.8.app.0.33c0d9d")

;set data
_UIA_action(".mainwindow", "setfocus")
_UIA_action(".mainwindow", "type", "12345")

;try to click or invoke
_UIA_action("OK.mainwindow", "setfocus")
;_UIA_action("OK.mainwindow","invoke")
_UIA_action("OK.mainwindow", "click")

From simplespy:

;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Cash Register Express -- Station: 01 -- Cashier: 100101 -- 4/24/2015 08:21 AM;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children)    
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children)  
_UIA_Action($oP0,"setfocus")
_UIA_setVar("OK.mainwindow","title:=OK;classname:=WindowsForms10.Window.8.app.0.33c0d9d")
_UIA_action("OK.mainwindow","setfocus")

Also, how do you clear an edit box before sending text to it? I tried _UIA_action(".mainwindow", "setvalue", "") with no luck.

Thanks.

Share this post


Link to post
Share on other sites

rename ok.mainwindow to okButton

.mainwindow has a special meaning and unfortunately has a bug so do not use it just give your elements a meaningfull name without .mainwindow

 

_UIA_Action($oP0, "setfocus") is just a wrapper to do $oP0.setfocus()

 

so you can either use the patterns of iUIAutomation of Microsoft

$tPattern = _UIA_getPattern($oP0, $UIA_ValuePatternId)
if _UIA_IsElement($tPattern) Then
$tPattern.setValue("")
EndIf

or try the other IUIWrapper actions

a."setValue using keys"

b."setValue using clipboard"

c."sendkeys", "enterstring", "type", "typetext"

its a little hard to say how to send empty string to be entered as it differs per textbox class what works best but as you are able to type text a 

1. select all with ^a

2. delete with {delete}

see send command in helpfile

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now