Jump to content

Ruby: AutoIt function HWnd not working in ruby?


anukul
 Share

Recommended Posts

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.

For e.g, for ControlSetText, I want to extract the Window Handle and use that for setting the text rather than title as the first argument:

autoIt.ControlSetText(appHandle,"","Edit1","foobar")

Can anyone tell what is wrong in the above code snippet? Or am I missing

something to make it work.

Thanks,

Anukul

Link to comment
Share on other sites

  • Moderators

I do not see HWND as an option in the AutoItX.chm... Stands to reason you would get the error.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I do not see HWND as an option in the AutoItX.chm... Stands to reason you would get the error.

You can use handles (or strings representing handles) like this in Ruby:

require 'win32ole'

ax3 = WIN32OLE.new("AutoItX3.Control")

ax3.AutoItSetOption("WinTitleMatchMode",4)

handles=[]

3.times do

ax3.run("notepad.exe")

sleep 0.1

app_handle = ax3.WinGetHandle("[ACTIVE]")

handles << "[HANDLE:#{app_handle}]"

end

#do some tricks with each notepad-instance

x,y = 100,100

handles.each do |handle|

ax3.ControlSetText(handle, "", "Edit1", "Hurray from #{handle}")

ax3.WinSetTitle(handle, "", handle)

ax3.WinMove(handle,"",x,y,250,250)

x += 250

end

sleep 5

# close them

handles.each do |handle|

ax3.winclose(handle)

end

hth,

Siep

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...