Jump to content
JPQ

Problem returning Windows form textbox contents to AutoIT - (Moved)

Recommended Posts

JPQ

I am having a tough time trying to determine if I need ControlGetText or another function to return to my running script, the value in a text box in a form in a running Windows application.

The control has no name and I have attempted to use the extended control method including what is available for the text box on the form; all to no avail.

I realize there is a lot of trial and error here, but am I heading down the right path? Do I need to do a ControlSetText first (pretty sure I tried that to no avail.)

Thank you.

Share this post


Link to post
Share on other sites
JLogan3o13

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jdelaney

Submit your attempts and the spy tool output.  add error handling after every function to see what specifically is failing.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
JPQ
Posted (edited)

There were multiple attempts (mostly commented out in the attached). I am getting the handle returned but pretty sure something(s)  additional is missing here.

I have clawed and scraped (ok not literally) through the navigation of three (3) separate Windows form to get to this one where I need to potentially modify an accounts address with a new one I have in an Excel file (reading this file already working too). This includes one form where I paste the contents of one Excel cell to a form and click on a radio  button.

Thank you in advance.

Go_Next_20180628_004.au3

AutoIT snip_20180628.PNG

Edited by JPQ
Further notees

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

Pass on downloading files from non-trusted sources.

use the ID: 1031

$hWin = WinGetHandle("Edit Patient Information")
If Not IsHWnd($hWin) Then
    ConsoleWrite("WinGetHandle failed to find a window" & @CRLF)
    Exit
EndIf
ConsoleWrite("$hWin=" & $hWin & @CRLF)

$hControl = ControlGetHandle($hWin,"",1031)
If Not IsHWnd($hControl) Then
    ConsoleWrite("ControlGetHandle failed to find control")
    Exit
EndIf
ConsoleWrite("$hControl=" & $hControl & @CRLF)

$sText = ControlGetText($hWin,"",$hControl)
ConsoleWrite("$sText=" & $sText & @CRLF)

 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
JPQ

So I have been able to get the handle of the Window (after researching and found I would need to use Opt("WinTitleMatchMode", 4) but now I'm unable to get the handle of the particular control on the form whose handle I just successfully retrieved.

The parameters I am using for the individual control seem to change every time I open this form. I think I may have to loop through all the controls on this form (which may be a child form in itself) to see if there's any other way to consistently reference this and all the other controls (all text boxes) I need to access.

Having consulted with a Windows forms developer on my work team, it appears these controls are being somewhat reused, thus causing the Instance #'s for instance to change.

Can someone point me to the proper function to be able to list out all child elements?

 

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

You can use my signature as an example of looping through all controls in a window.  I'm doubtful that the id will change.   fyi, developing on instance based counters will break evetime a new control is added or removed.   I'd suggest not doing that.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
JPQ

Will check this out for sure. Thank you for the direction. 

Share this post


Link to post
Share on other sites
JPQ

So i downloaded the simplespy.au3 script from elsewhere on the AutoIT website, and ran this against one of the text boxes on the form that I m trying to "read" from. I am attaching the results of that here. 

Based on what you can have the time to review here, would you (in your opinion) further attempt to complete a script where I am reviewing any/all address related text boxes against an Excel file which has potentially new/changed addresses. I may have to revisit this later and take on a less onerous multi-form, multi-click scenario,

It would be a shame but eventually I will have to move on. BTW: The contents of the address field in the attached is found here "UIA_iaccessiblevalue:= <1521 N 1350 W>".

Thank you for your help and honest feedback.

new Spy Report_20180702.txt

Share this post


Link to post
Share on other sites
jdelaney

Just paste in the contents.  I refuse to download attachments.  or wait for someone else to


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
JPQ
Posted (edited)

Here you go:

 

    https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373
At least we have an element title: [] class: [Edit]

Having the following values for all properties: 
 

Title is: <>    Class   := <Edit>    controltype:= <UIA_EditControlTypeId>    ,<50004>    , (0000C354)    345;392;160;18
*** Parent Information top down ***
5: Title is: <Intergy - Aegis Sciences Corporation - User Name>    Class   := <WindowsForms10.Window.8.app.0.1d2098a_r46_ad1>    controltype:= <UIA_WindowControlTypeId>    ,<50032>    , (0000C370)    0;0;1359;688
"Title:=Intergy - Aegis Sciences Corporation - User Name;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1""    
4: Title is: <>    Class   := <WindowsForms10.Window.8.app.0.1d2098a_r46_ad1>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    8;86;1343;594
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1""    
3: Title is: <Edit Patient Information>    Class   := <ProMainWin>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    288;174;783;456
"Title:=Edit Patient Information;controltype:=UIA_PaneControlTypeId;class:=ProMainWin""    
2: Title is: <>    Class   := <ProClientWin>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    291;219;777;408
"Title:=;controltype:=UIA_PaneControlTypeId;class:=ProClientWin""    
1: Title is: <>    Class   := <ProFrame>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    291;219;777;408
"Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame""    
0: Title is: <>    Class   := <ProFrame>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    294;225;673;399
"Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame""    

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

_UIA_setVar("oP1","Title:=Intergy - Aegis Sciences Corporation - User Name;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1")    ;Intergy - Aegis Sciences Corporation - User Name
_UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1")    ;
_UIA_setVar("oP3","Title:=Edit Patient Information;controltype:=UIA_PaneControlTypeId;class:=ProMainWin")    ;Edit Patient Information
_UIA_setVar("oP4","Title:=;controltype:=UIA_PaneControlTypeId;class:=ProClientWin")    ;
_UIA_setVar("oP5","Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame")    ;
_UIA_setVar("oP6","Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame")    ;

_UIA_setVar(".mainwindow","title:=;classname:=Edit")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")
;~_UIA_Action("oP5","highlight")
_UIA_Action("oP5","setfocus")
;~_UIA_Action("oP6","highlight")
_UIA_Action("oP6","setfocus")

_UIA_action(".mainwindow","setfocus")


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

Local $oP5=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Intergy - Aegis Sciences Corporation - User Name;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1", $treescope_children)    
_UIA_Action($oP5,"setfocus")
Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.1d2098a_r46_ad1", $treescope_children)    
_UIA_Action($oP4,"setfocus")
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=Edit Patient Information;controltype:=UIA_PaneControlTypeId;class:=ProMainWin", $treescope_children)    
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ProClientWin", $treescope_children)    
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame", $treescope_children)    
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ProFrame", $treescope_children)    
_UIA_Action($oP0,"setfocus")
_UIA_setVar(".mainwindow","title:=;classname:=Edit")
_UIA_action(".mainwindow","setfocus")


*** Detailed properties of the highlighted element ***
UIA_class:= <Edit>
UIA_regexpclass:= <Edit>
UIA_iaccessiblevalue:= <1521 N 1350 W>
UIA_iaccessiblechildId:= <0>
UIA_id:= <213>
UIA_handle:= <658108>
UIA_RuntimeId:= <42;658108>
UIA_BoundingRectangle:= <345;392;160;18>
; Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

 

Edited by JLogan3o13

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

Oh, that's uia...just use the spytool that comes with autoit or my signature function. ..uia is the last resort for when standard functions don't apply (my opinion)

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
JPQ

OK. Started to play with GetAllWindowsControls (looks quite promising); updates to follow.

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

×