# Equivalent of "click\_no\_wait" using win32ole and threads?

**URL:** <https://www.ruby-forum.com/t/equivalent-of-click-no-wait-using-win32ole-and-threads/159627>\
**Category:** Ruby\
**Created:** [February 6, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/equivalent-of-click-no-wait-using-win32ole-and-threads/159627 "2009-02-06T13:57:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [February 6, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/equivalent-of-click-no-wait-using-win32ole-and-threads/159627/1 "2009-02-06T13:57:15Z")

</div>

Hi guys,

I have a watir script to download few files. In the script I am  
currently using “click\_no\_wait” to download which is working fine.  
But if I remove the download file from the backend and then run my  
script. The script will hang as because “click\_no\_wait” expects a  
download popup to show. I want my script to be full proof.

So I want something equivalent to “click\_no\_wait”. I have tried using  
threads and win32ole library to achieve the same. With the code bellow I  
have almost succeeded. This code can click and download the file. The  
problem with the code bellow is that both the threads “t” and “s” still  
runs after its job is done (does not join with the main thread). I am  
not able to figure out why?.

* * *

#require

#download\_file()  
#download the file into the given path  
def download\_file(filepath)  
ai = WIN32OLE.new(“AutoItX3.Control”)  
ret = ai.WinWaitActive($wintitle[‘502’], “”, $sleeptime)  
ai.WinWait($wintitle[‘502’], “”, $sleeptime)  
ai.ControlFocus($wintitle[‘502’], “”, “&Save”)  
sleep 1  
ai.ControlClick($wintitle[‘502’], “”, “&Save”, “left”)  
ai.WinWait($wintitle[‘503’], “”, $sleeptime)  
sleep 1  
ai.ControlSend($wintitle[‘503’], “”, “Edit1”, filepath)  
sleep 1  
ai.ControlClick($wintitle[‘503’], “”, “&Save”, “left”)  
sleep 1  
# wait for the window to manually close after download. Time out,  
# as that might be the case when browser download window  
automatically  
# closes the window with option “Close the dialog box when download  
completes”  
# or something similar.  
ret = ai.WinWaitActive($wintitle[‘504’], “Close”, $maxsleeptime)  
sleep 1  
if ret == 1  
ai.ControlClick($wintitle[‘504’], “”, “Close”)  
end  
sleep 1  
end #end of download\_file()

## ie = Watir::Browser.new ie.goto “[http://myportal/downloads](http://myportal/downloads)” ie.wait #click on download guide t = Thread.new(){ ie.link(:text, /Download guide/).click } s = Thread.new(){ sleep 30 download\_file(“c:\downloads\guide.doc”) } t.join s.join

Please suggest, what is that I am doing wrong. Also let me know if there  
is other alternatives.

Thanks in Advance,  
Mandeep
