AutoIt: HWnd function of AutoIt giving method missing error

A

Anukul Singhal

Hi,

I am using AutoIt in my ruby code to automate a client
application.Although most of the AutoIt methods are working fine, I am
not able to use the HWnd function of AutoIt, getting a method missing
error. Would like to know if there is anything wrong in the code below:

require 'win32ole'

autoIt = WIN32OLE.new("AutoItX3.Control")
bb = IO.popen("C:/Windows/Notepad.exe")
sleep 3.0
appID = autoIt.WinGetHandle("Untitled -Notepad")
sAppID = appID.to_s
appHandle = autoIt.HWnd(sAppID)
puts appHandle

The above piece of code gives me this error:

1) Error:
test_client_actions_click_positive(Client_unit_test):
WIN32OLERuntimeError: unknown property or method `HWnd'
HRESULT error code:0x80020006
Unknown name.

Although HWnd is a supported method for AutoIt, I am getting this error.

I know I can use the title arg for performing my actions, but my
requirement is to get the WindowHandle and use it to perform actions
like ControlSetText and ControlClick, etc.

Can anyone tell what is wrong in the above code snippet? Or am I missing
something to make it work.

Thanks,
Anukul
 
S

Siep Korteling

Anukul said:
Hi,

I am using AutoIt in my ruby code to automate a client
application.Although most of the AutoIt methods are working fine, I am
not able to use the HWnd function of AutoIt, getting a method missing
error. Would like to know if there is anything wrong in the code below:

require 'win32ole'

autoIt = WIN32OLE.new("AutoItX3.Control")
bb = IO.popen("C:/Windows/Notepad.exe")
sleep 3.0
appID = autoIt.WinGetHandle("Untitled -Notepad")
sAppID = appID.to_s
appHandle = autoIt.HWnd(sAppID)
puts appHandle

When this line is inserted:

puts autoIt.ole_methods

it shows there is no method Hwnd.

AFAIK WinGetHandle is already giving you what you want. If you need the
handle from a control (f.i. a button or label) , use ControlGetHandle.

hth,

Siep
 
A

Anukul Singhal

Hi Siep,

Thanks a lot for the reply. You are right that WinGetHandle or
ControlGetHandle should do the trick for me. But my requirement is to
use one of these handles to set text or do the click operation. What I
want to do is this:

appID = autoIt.WinGetHandle("Untitled -Notepad")
autoIt.ControlSetText(appID,"","Edit1","This is a text")

I want to use title argument only once to fetch the window handle and
then subsequently use the window handle to perform other actions of
setting text or click. Is it possible to avoid 'title' argument and use
a Window Handle instead?
My concern is that if there are more than 1 instance of say "Notepad",
the title of all the instances of notepad would be the same but the
Window Handle would be unique for each instance, and hence would be a
good option to use for performing actions.

Is there any way out to do the above step and avoid "title" as the first
argument?

Thanks,
Anukul
 
M

Masaki Suketa

Hello,

Anukul said:
autoIt = WIN32OLE.new("AutoItX3.Control")
bb = IO.popen("C:/Windows/Notepad.exe")
sleep 3.0
appID = autoIt.WinGetHandle("Untitled -Notepad")
sAppID = appID.to_s
appHandle = autoIt.HWnd(sAppID)
puts appHandle

The above piece of code gives me this error:

1) Error:
test_client_actions_click_positive(Client_unit_test):
WIN32OLERuntimeError: unknown property or method `HWnd'
HRESULT error code:0x80020006
Unknown name.

Although HWnd is a supported method for AutoIt, I am getting this error.

I think HWnd is a function for AutoIt script, but HWnd is not
included in AutoItX3.Control.
HWnd is not included the ole_methods list.

autoIt = WIN32OLE.new("AutoItX3.Control")
p autoIt.ole_methods

How about asking AutoIt Team whether HWnd is included in
AutoItX3.Control or not?
Or Asking AutoIt Team how to call HWnd from VBScript.
If you can call HWnd from VBScript, you could call HWnd from Win32OLE.

Regards,
Masaki Suketa
 
S

Siep Korteling

Anukul said:
Hi Siep,

Thanks a lot for the reply. You are right that WinGetHandle or
ControlGetHandle should do the trick for me. But my requirement is to
use one of these handles to set text or do the click operation. What I
want to do is this:

appID = autoIt.WinGetHandle("Untitled -Notepad")
autoIt.ControlSetText(appID,"","Edit1","This is a text")

I want to use title argument only once to fetch the window handle and
then subsequently use the window handle to perform other actions of
setting text or click. Is it possible to avoid 'title' argument and use
a Window Handle instead?
My concern is that if there are more than 1 instance of say "Notepad",
the title of all the instances of notepad would be the same but the
Window Handle would be unique for each instance, and hence would be a
good option to use for performing actions.

Is there any way out to do the above step and avoid "title" as the first
argument?

Found an undocumented feature. This is a way to use the handle:

res=autoIt.ControlSend("[HANDLE:#{appID}]","","Edit1","some text")
sleep 2
autoIt.Winclose("[HANDLE:#{appID}]")

hth,

Siep
 
A

Anukul Singhal

Hi,

Thanks so much. It worked great! Just want to know if you have the url
or any reference where you got these undocumented features from?

Thanks,
Anukul

Siep said:
Anukul said:
Hi Siep,

Thanks a lot for the reply. You are right that WinGetHandle or
ControlGetHandle should do the trick for me. But my requirement is to
use one of these handles to set text or do the click operation. What I
want to do is this:

appID = autoIt.WinGetHandle("Untitled -Notepad")
autoIt.ControlSetText(appID,"","Edit1","This is a text")

I want to use title argument only once to fetch the window handle and
then subsequently use the window handle to perform other actions of
setting text or click. Is it possible to avoid 'title' argument and use
a Window Handle instead?
My concern is that if there are more than 1 instance of say "Notepad",
the title of all the instances of notepad would be the same but the
Window Handle would be unique for each instance, and hence would be a
good option to use for performing actions.

Is there any way out to do the above step and avoid "title" as the first
argument?

Found an undocumented feature. This is a way to use the handle:

res=autoIt.ControlSend("[HANDLE:#{appID}]","","Edit1","some text")
sleep 2
autoIt.Winclose("[HANDLE:#{appID}]")

hth,

Siep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top