Jump to content

How to find a control if ID duplicates


Recommended Posts

Can you please tell us which application you try to automate?

I could provide all the infomation of the application to you.

But now I just need make a progress. And I have already found some hope from the document, https://www.autoitscript.com/autoit3/docs/intro/controls.htm

It says we can identify a control by position and size. But this piece of code just not work

$hWnd = WinWait("[W:423; H:323]")
ConsoleWrite($hWnd & @CRLF)

Local $sText = ControlGetText($hWnd, "", "[ID:323]")
ConsoleWrite($sText & @CRLF)

Local $sText2 = ControlGetText($hWnd, "", "[X:150; Y:70; W:50; H:16]")
ConsoleWrite($sText2 & @CRLF)

Could you please tell me what is the right way to do this. Thanks a lot.

Link to comment
Share on other sites

You do not try to access the same controls as you have posted in the screenshots?
What is the value of @error after calling ControlgetText.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This works for me:

#include <Array.au3>
$aPos = WinGetPos("Unbenannt - Editor") ; Get the position of the Window
_ArrayDisplay($aPos)
$hWnd = WinGetHandle("[X:139; Y:341; W:638; H:438]") ; Values taken from the _ArrayDisplay
$aPos = ControlGetPos($hWnd, "", 15) ; Get the position of the Control. The same values as taken from AutoIt Window Info Tool
_ArrayDisplay($aPos)
$sText = ControlGetText($hWnd, "", "[X:0; Y: 0; W:622; H:380]")
ConsoleWrite($sText & @CRLF)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Appears it works on some controls, not others.

Here is how I tested on only open explorer window...

$hwnd = WinActivate("[Class:CabinetWClass]", "")

$val = ControlGetText($hwnd, "", "[X:72; Y:5; W:914; H:22]") ; does not work

;$val = ControlGetText($hwnd, "", "[CLASS:ToolbarWindow32; INSTANCE:2]") ; works

ConsoleWrite($val & @LF & @error & @LF)

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Did you check that $hWnd is a handle by using IsHWnd?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...