Sign in to follow this  
Followers 0
SmokeyDaBears

Script Stalling on File Open Dialog

15 posts in this topic

Ok a little back information on the script. I work for a medical practice and we have to have patients sign their HIPAA consent form, then we have to save it to a pdf and attach it into their records. Everything in the script works flawlessly and saves the ladies so much time at the front desk. Here is where my problem comes in. One of the very last steps is to open the patients record, right click and do attach to attach the file. A file open dialog opens up then the script enters the name of the file and clicks save. About 9 times out of 10, the script will stall right at this point. I tried turning on the TrayIconDebug, along with other things. It doesn't error out or nothing, the script just stops. Even if I go and select the file manually hoping the script will continue on after I do that, nothing. It just stops. Searched the forums for a little bit and couldn't find much about it. I was searching for something else the other day and saw someone else have same problem, but can't find it of course when I'm looking for it. Attaching the code and a screenshot of where it stalls out. Thanks guys.

Posted Image

And the code:

CODE
#Include <Date.au3>

Opt("GUICoordMode",2)

Opt("SendKeyDelay",30)

Opt("TrayIconDebug", 1)

;~ Opt('WinSearchChildren', 1)

$first = ControlGetText("[CLASS:TPatientForm]", "", "[CLASS:TDBEdit; INSTANCE:14]")

$last = ControlGetText("[CLASS:TPatientForm]", "", "[CLASS:TDBEdit; INSTANCE:15]")

$date = _NowDate()

BlockInput (1)

Run("hipaa.bat", "")

WinWaitActive("hipaa.pdf")

Send("{TAB}")

Sleep("200")

Send("{Enter}")

BlockInput (0)

WinWaitActive("Signature Capture")

WinWaitClose("Signature Capture")

WinActivate("hipaa.pdf")

WinWaitActive("hipaa.pdf")

BlockInput (1)

WinWaitActive("hipaa.pdf")

Sleep("600")

WinWaitActive("hipaa.pdf")

Send("{TAB}")

Send($date)

Sleep("500")

Send("{TAB}")

Sleep("1000")

Send($first)

Sleep("500")

Send("{SPACE}")

Sleep("500")

Send($last)

Sleep("200")

Send("{TAB}")

Sleep("200")

Send("^p")

WinWaitActive("Print")

Sleep("500")

Send("^b")

Sleep("500")

Send("{ENTER}")

WinWaitActive("Save PDF Document As")

Send($last)

Sleep("200")

Send("{ENTER}")

WinActivate("hipaa.pdf")

WinWaitActive("hipaa.pdf")

Sleep("500")

Send("!o")

Sleep("200")

Send("{Down 8}")

Sleep("500")

Send("{Enter}")

WinWaitActive("hipaa.pdf")

Sleep("200")

Send("^q")

WinWaitActive("Adobe Acrobat")

Send("y")

WinActivate("[CLASS:TPatientForm]", "")

WinWaitActive("[CLASS:TPatientForm]")

Sleep(500)

ControlClick ( "[CLASS:TPatientForm]", "", "[CLASS:TcxGridSite]" )

Sleep("300")

Send("!t")

Sleep("700")

ControlClick ( "[CLASS:TPatientForm]", "", "[CLASS:TcxGridSite]", "right" )

Send("{DOWN 2}")

Sleep("200")

Send("{ENTER}")

Sleep(500)

;~ WinActivate("Open")

Sleep(1000)

ControlClick ( "Open", "", "Edit" )

Sleep(200)

;~ ControlSend("Open", "", "Edit", "P:\forms\")

Send("P:\forms\")

Sleep("100")

;~ ControlSend("Open", "", "Edit", $last)

Send($last)

Send("{ENTER}")

WinWaitActive("Attachment Description")

WinActivate("Attachment Description")

Send("HIPAA and Financial Agreement")

Sleep("200")

Send("{ENTER}")

BlockInput (0)

If @error Then MsgBox(16, "Error", "Run() produced and error:" & @CRLF & _GetLastErrorMessage ())

Func _GetLastErrorMessage($DisplayMsgBox="")

Local $ret,$s

Local $p = DllStructCreate("char[4096]")

Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000

If @error Then Return ""

$ret = DllCall("Kernel32.dll","int","GetLastError")

$ret = DllCall("kernel32.dll","int","FormatMessage", _

"int",$FORMAT_MESSAGE_FROM_SYSTEM, _

"ptr",0, _

"int",$ret[0], _

"int",0, _

"ptr",DllStructGetPtr($p), _

"int",4096, _

"ptr",0)

$s = DllStructGetData($p,1)

$p = 0

If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)

return $s

EndFunc

Func input()

BlockInput (0)

EndFunc

Share this post


Link to post
Share on other sites



Can you use ControlSend instead of just Send? And/or instead of using sleeps why not winwaitactive? (I see you commented them out, did you try that and couldn't get it working?)

This is the part of your code your talking about...

ControlClick ( "[CLASS:TPatientForm]", "", "[CLASS:TcxGridSite]", "right" )
Send("{DOWN 2}")
Sleep("200")
Send("{ENTER}")
Sleep(500)
;~ WinActivate("Open")
Sleep(1000)
ControlClick ( "Open", "", "Edit" )
Sleep(200)
;~ ControlSend("Open", "", "Edit", "P:\forms\")
Send("P:\forms\")
Sleep("100")
;~ ControlSend("Open", "", "Edit", $last)
Send($last)
Send("{ENTER}")
WinWaitActive("Attachment Description")
WinActivate("Attachment Description")

Why do you have WinWaitActive and then WinActivate? The script won't continue until "Attachment Description" is active anyway, so reactivating it immediately after checking won't do anything.

Two more things... you said you used trayicondebug, was there a line of code your script was halting on? What happened with it? Also, with your controlclick commands, you can check for an error which could tell you something went wrong with your Send commands (that is if you have to use Send).


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Can you use ControlSend instead of just Send? And/or instead of using sleeps why not winwaitactive? (I see you commented them out, did you try that and couldn't get it working?)

This is the part of your code your talking about...

ControlClick ( "[CLASS:TPatientForm]", "", "[CLASS:TcxGridSite]", "right" )
Send("{DOWN 2}")
Sleep("200")
Send("{ENTER}")
Sleep(500)
;~ WinActivate("Open")
Sleep(1000)
ControlClick ( "Open", "", "Edit" )
Sleep(200)
;~ ControlSend("Open", "", "Edit", "P:\forms\")
Send("P:\forms\")
Sleep("100")
;~ ControlSend("Open", "", "Edit", $last)
Send($last)
Send("{ENTER}")
WinWaitActive("Attachment Description")
WinActivate("Attachment Description")

Why do you have WinWaitActive and then WinActivate? The script won't continue until "Attachment Description" is active anyway, so reactivating it immediately after checking won't do anything.

Two more things... you said you used trayicondebug, was there a line of code your script was halting on? What happened with it? Also, with your controlclick commands, you can check for an error which could tell you something went wrong with your Send commands (that is if you have to use Send).

Some of the extra Winactivate's and stuff like that, anything that's commented out were just different experiments to see if it would fix the problem. With the debug thing, the tray gives me no messages at all, doesn't tell me what line it's on or anything. It stops right when the 'Open' dialog pops up. And it doesn't act like it pauses, more like the program just stops all together, like it isn't registering that the Open dialog came up. The script continues to run, but won't do anything. I even tried manually closing the open dialog and reopening it by hand, but the program will not continue at all.

Share this post


Link to post
Share on other sites

Well if the above code is where the error is, the code should keep going until WinWaitActive("Attachment Description"). The reason is Send() doesn't wait or return anything in an 'error' (its not really an error, just not doing what you expected). Since it doesn't wait, closing/reopening the 'open' window won't do anything as your script has already moved on. If you really can't use ControlSend, you will need to rely on winwait functions to know whats going on.

As for trayicondebug...it should show what line of code your program is on when you hover over the icon, but trayicons can be buggy. Put #AutoIt3Wrapper_run_debug_mode=Y at the top of your script; that will spit out line for line what your code is doing into the console. It can be a little overkill but it should show you where your script is ultimitely stopping.

What I would suggest you do is replace every Send you can with ControlSend, and where not possible put Winwait() commands and as I said above, check your controlclick command like so,(quick code but you get the gist)

ControlClick ( "Open", "", "Edit" )

if @error then msgbox(0, "", "error")

The problem is 99% likely to come from Send() sending the keystrokes while the window isn't active, the cursor isn't in the box...etc.

Am I making sense? Having one of those days...


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

And while that makes sense, the original version was all controlsends, but it still did the stall thing. The script stops right when the open dialog comes up. So even if I close the open dialog and reopen it, if the script has moved on like you said, when I manually enter in the file name and press save and the description box comes up, the script should continue, but it doesn't.

Share this post


Link to post
Share on other sites

Line #50 'Send("!o")' seems to be the last command that definitely executes successfully. Since line #55 'WinWaitActive("hipaa.pdf")' never activates . That means it is hanging in this block of code.

Send("!o")
Sleep("200")
Send("{Down 8}")
Sleep("500")
Send("{Enter}")
WinWaitActive("hipaa.pdf")
Sleep("200")
Send("^q")
WinWaitActive("Adobe Acrobat")

In fact if you could explain exactly what

Send("{Down 8}")

Send("{Enter}")

WinWaitActive("hipaa.pdf")

Send("^q")

WinWaitActive("Adobe Acrobat")

actually accomplishes it would be a big help.

I can't follow what the computer is actually supposed to do on these steps. It opens a file open dialog box, then 'Send("{Down 8}")' to do what? The down key does nothing on an open file diolog on my computer. Oh, wait. Are you depending on the open MRU to contain the file path? Even so the dropdown box must be activated before it will scroll on my machine. The MRU also changes depending on the last operation with the file open dialog. Couldn't you just send the filename 'hipaa.pdf' directly to the filename box, it is the default location for text input? Then 'Send("^q")' quits the application (even though nothing was done) but the very next line waits on "Adobe Acrobat".

Perhaps replacing 'Send("{Down 8}")' with 'Send("hipaa.pdf")' to select the file to open will fix it. With some work that script could run comparatively blazing fast with much less code and a lot more dependability. It helps to work with objects rather than sendkeys whenever possible.

Share this post


Link to post
Share on other sites

That section of code goes into the menu on Acrobat and clears out the form. When you clear the form it loses focus for about a second, then comes back into focus, then the ^q closes acrobat. It brings up a Dialog called Adobe Acrobat that is asking you to save the file.

Share this post


Link to post
Share on other sites

And while that makes sense, the original version was all controlsends, but it still did the stall thing. The script stops right when the open dialog comes up. So even if I close the open dialog and reopen it, if the script has moved on like you said, when I manually enter in the file name and press save and the description box comes up, the script should continue, but it doesn't.

In that same code segment;

Send("!o")
Sleep("200")
Send("{Down 8}")
Sleep("500")
Send("{Enter}")
WinWaitActive("hipaa.pdf")
Sleep("200")
Send("^q")
WinWaitActive("Adobe Acrobat")

1) You open a file open dialog. -- Send("!o")

2) You select the filename . -- Send("{Down 8}")

3) You open the file. -- Send("{Enter}")

4) You wait on it to be active. -- WinWaitActive("hipaa.pdf")

5) You close the file. -- Send("^q")

But wait, why did you open it in the first place if all you were going to do it close it as soon as it opened?

Also "hipaa.pdf" was already open before any open dialog routine. If it was something other than "hipaa.pdf" you opened it's pointless to wait on "hipaa.pdf" to be active.

Also when you close it you wait on "Adobe Acrobat" to be active. Why? You just quit whatever application was active. Is there more than one instance of Adobe running?

It seems that 'WinWaitActive("Adobe Acrobat")' is the file save dialog that prompts to save unsaved changes, but you just opened it 3 steps before with 'BlockInput (1)' and no autoit input.

What are you opening with 'Send("{Down 8}")' and why?

Share this post


Link to post
Share on other sites

No no no. The Alt O opens the form menu in Acrobat, the down 8 takes it down to the Clear form option, and enter selects it. This is a PDF form that they sign with a digital signature pad. I have to clear the form before I close acrobat, otherwise even if you save or dont save the file when closing it, the signature stays in there.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Ok, my bad. I understand what's happening now. I misread the 'Send("!o")'. The actual problem starts after 'ControlClick ( "Open", "", "Edit" )'.

It's possible that 'Send("P:\forms\")' gets executed before the open dialog is activated. However the main issue, you then 'WinWaitActive("Attachment Description")' before you 'WinActivate("Attachment Description")' causing the indefinite wait.

Reverse:

WinWaitActive("Attachment Description")

WinActivate("Attachment Description")

Share this post


Link to post
Share on other sites

#11 ·  Posted

I just noticed the changelog for autoit v3.2.10.0

Fixed: WinWaitActive() sometimes failing after a WinActivate().

What version are you using?

Share this post


Link to post
Share on other sites

#12 ·  Posted

I just noticed the changelog for autoit v3.2.10.0

Fixed: WinWaitActive() sometimes failing after a WinActivate().

What version are you using?

I'm using the latest beta.

Share this post


Link to post
Share on other sites

Sorry for re-opening an old thread everyone, but I seem to be having nearly the exact same problem as SmokeyDaBears and I cannot seem to find any more information about this issue!

I am using AutoIT (v3.2.12.1) as a test tool for my application. I wrote my test scripts on two separate machines, and on either of those machines they run cleanly without any problem, whether running in .au3 format or compiled script format. However, when I moved to my customer test bed (which is identical to one of my two dev machines except that it has 1Gb less ram) I get the same kind of occasional stall or hang on File->Open inside my application. (Error happens with both script and compiled script.)

I call it an occasional failure because it seems to randomly happen. Sometimes it will happen 2-3 times when running 10 times, othertimes not at all when I run the script 20 times!

Based on logging messages that I have added to my script, I know that the script is running away even though the application is paused - i.e. that the script continues to run even though the application is hung at the File->Open menu. I even added a return code check for each item from ControlSetText on and they ALL pass!

CODE
; 1. start my app

Run("myApp.exe")

$retval = WinWaitActive($TITLE_MAIN_WIN, "Ready")

if ($retval == 0) then

Exit(-1)

EndIf

; 2. File->Open window (this bit does some extra checking to try to make sure it waits for the dialog to be open!)

Send("!fo")

; $TITLE_OPEN = "Open"

if not WinActive( $TITLE_OPEN ) Then

WinActivate( $TITLE_OPEN )

EndIf

$retval = WinWaitActive( $TITLE_OPEN,"",2)

if (0 == $retval) then

WinClose($TITLE_MAIN_WIN)

WinWaitClose($TITLE_MAIN_WIN, "", 2)

exit(-1)

EndIf

;put image file name File name edit box, click Open button

;Edit1 is the field to put in the filename in. It is right since my script usually works

ControlSetText($TITLE_OPEN, "", "Edit1", $imagefile)

;Button2 is the "Open" button - I have the right button since my script usually works

ControlClick($TITLE_OPEN, "", "Button2")

; Do other processing - which my script definitely gets to even when the application is still waiting on the File Open dialog.

Can anyone help? To summarize, my application is hanging at the File->Open dialog box, with no text entered in the filename field. The script keeps right on going, thinking that it has already entered the filename and clicked on OK.

Thanks.

Share this post


Link to post
Share on other sites

Update: I've been fighting this problem for several days now, but thanks to a few other posts I read, I had some ideas.

For those with a similar problem, this will explain what I tried and what's worked (so far)

First, I split the file and the open and added short sleeps:

CODE

Send("!f")

Sleep(200)

Send("o")

Sleep(200)

...

Next, when I proved this worked, I moved back to my original File Open mechanism, removed the sleeps and I modified this environment var instead:

CODE

Opt("SendKeyDelay", 200)

So far, in a loop of nearly 500 iterations, I have not seen the failure!

So it seems that the stall / hang on File->Open has something to do with the delay after sending data to the dialog. Tonight I will run with a longer loop to ensure the problem is gone. I will follow up to let you know how it turns out.

Share this post


Link to post
Share on other sites

Final update. I hope this helps someone else sometime who was struggling as much as I was with this randomly appearing problem.

The SendKeyDelay seems to have resolved the problem. My overnight test did 8000 loops with no trouble.

It appears that for my troublesome testbed system I need to have the delay set to 200ms (I made it a configuration file item so I don't need to recompile my test scripts). I tried at 100ms and my test suite still had some hang / stalls on File->Open.

Cheers.

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
Sign in to follow this  
Followers 0