Jump to content

WinWait problem?


Recommended Posts

Hi all, i have a weird problem, i have made a script that waits for a window to popup before continue, it works as a standalone but not inside the bigger script and i can´t figure out why.

Here´s the standalone script:

WinWait("Kampanj -- Webpage Dialog", "")
    If WinExists("Kampanj -- Webpage Dialog", "") Then
   MsgBox(0,"KAMPANJ!","Kampanjfönster öppet")
   WinActivate("Kampanj -- Webpage Dialog", "")
   Send("{ALTDOWN}s")
   Sleep(100)
   Send("{ALTUP}")
   Sleep(100)
   Send("{ALTDOWN}t")
   Sleep(100)
   Send("{ALTUP}")
   Sleep(100)
   EndIf

And here´s the bigger script where this code just waits forever when it gets to the winwait:

#include <IE.au3>
#include <File.au3>
#include <Misc.au3>
#include <Excel.au3>
$g_szVersion = "blob"
If WinExists($g_szVersion) Then Exit ; do NOT run me again!
AutoItWinSetTitle($g_szVersion)
Global $kampanj
Global $rownr
Global $oIE
Global $oFrame
Global $ClipboardData
$rownr = 1
$oIE = _IEAttach("GSM-AHS")
WinActivate("GSM")
Sleep(50)
$kampanj = "KAM02370"
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.LIST.value = $kampanj
Sleep(5000)
$oFrame = _IEFrameGetCollection($oIE, 2)
$ClipboardData = _IEPropertyGet($oFrame, "outerhtml")
If StringInStr($ClipboardData, "selected value=KAM02370") Then
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.AddButton.disabled = False
sleep(1000)
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.AddButton.click
EndIf

WinWait("Kampanj -- Webpage Dialog", "")
    If WinExists("Kampanj -- Webpage Dialog", "") Then
   ;MsgBox(0,"KAMPANJ!","Kampanjfönster öppet")
   WinActivate("Kampanj -- Webpage Dialog", "")
   Send("{ALTDOWN}s")
   Sleep(100)
   Send("{ALTUP}")
   Sleep(100)
   Send("{ALTDOWN}t")
   Sleep(100)
   Send("{ALTUP}")
   Sleep(100)
   EndIf

Im planning on using it with various diffrent webapplications and local server programs and files, that´s why all thoose includes

any thoughts?

Link to comment
Share on other sites

When you say the stand-alone works ok, did you separate your full code into two portions, running the first portion of code, then waiting until the window appears before running the second (WinWait) portion?

It may be helpful to include a timeout in the WinWait call during testing at least.

Not being able to run your code myself with all that is necessary, it's a bit hard to troubleshoot, but it occurs to me, that you may have possibly meant to use the variable

$kampanj

instead of the text in your window title?

i.e. WinWait($kampanj & " -- Webpage Dialog", "")

Though that doesn't explain why the standalone works.

Other than that, I'd play around with your WinTitleMatchMode options, because if it's pausing at the point of window recognition, then you have to play around with your settings, until you get a match.

EDIT

Didn't have access to an AutoIt installation at the time, so I've corrected WinSetTitleMatch to WinTitleMatchMode.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Hi TheSaint, thanx for reply, the first codeblock is working on the page if i run it like it is and doing the first things manually that the bigger codeblock does, the second contains more stuff that also is working on the same page until it gets to the winwait (wich is exactly the same piece of code that is posted in the first block), and to answer your other question, the window name is exactly what it says in the winwait so it's not the $kampanj value i am after, just don't know what the problem is :/

Link to comment
Share on other sites

I would suggest not using waits. What if your processor is slow, and the wait isn't long enough. Such as, waiting for the button to enable. Use a loop until it is enabled. So clicking the button opens a second window? Just because the window opens, doesn't mean the html loaded. Use the _IE functions on the new window as well. (I would stay away from sends, also)

oh, another thought. It's possible that autoit is frozen, waiting for the dialog to close. Put a message box right after the winexists, and see if it displays.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Hey all, thanx for your advice, i have put msgboxes after winexists and it pops up if i run the first bit of code, but nothing in the other script because even if the window comes up just like it does when pressing the add button manually the winexists fail to see the window when the button is pressed with autoit code, so maybe the problem is with autoit simulating the press, the window might be different even if it doesn't show, ill try when i get back to work to do sendkeys on the button to see if it reacts any different

Link to comment
Share on other sites

No, I don't know the exact reason, but some of those pop-ups are modal to autoit...the script stops until the popup goes away.

If you send the click command through another process of autoit, then your driver script may proceed.

Look up, in the helpfile Command Line Parameters

option 4.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

like I said, i've came across the same issue. Such as when sending a commandid to a toolbar, which opens a window, the autoit script stops until that window is closed. If I performed the click manually, or had a second script click the toolbar, then the driver (the one that calls the second script) will not need to wait for the window to close (the second process does). Same for you.

similar thread:

example of usage...this is how i got around my issue (you will have to reformat to click the proper button:

Func WGe_SendToolbarCommandId($hCallersWindow, $hCallersToolbar, $iCallersCommandID)
 ;$giSubFunctionCounter += 1
 ;If $gbPerformLog Then Var_SetLogAndActOnState ( 2, 4, "WGe_SendToolbarCommandId()", "Func=[WGe_SendToolbarCommandId]: Start with Params=[" & $hCallersWindow & "," & $hCallersToolbar & "," & $iCallersCommandID & "].", $gbDisplayInformMessage, $gbTerminateOnFailure)
 If Not IsHWnd($hCallersToolbar) Then
  $hCallersToolbar = ControlGetHandle($hCallersWindow, "", $hCallersToolbar)
  If Not IsHWnd($hCallersToolbar) Then
   ;If $gbPerformLog Then Var_SetLogAndActOnState ( 0, 1, "WGe_SendToolbarCommandId()", "Func=[ControlGetHandle]: Unable to determin handle for the toolbar.", $gbDisplayMessage, $gbTerminateOnFailure)
   ;$giSubFunctionCounter -= 1
   Return False
  EndIf
 EndIf
 $sPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "ControlCommand ( hwnd(' & $hCallersWindow & '),'''', hwnd(' & $hCallersToolbar & '), ''SendCommandID'', ' & $iCallersCommandID & ' )"')
 If $sPID > 0 Then
  $bContinue = True
  ;If $gbPerformLog Then Var_SetLogAndActOnState ( 1, 1, "WGe_SendToolbarCommandId()", "Func=[WGe_SendToolbarCommandId]: Sent CommandID=[" & $iCallersCommandID & "].", $gbDisplayMessage, $gbTerminateOnFailure)
 Else
  $bContinue = False
  ;If $gbPerformLog Then Var_SetLogAndActOnState ( 0, 1, "WGe_SendToolbarCommandId()", "Func=[WGe_SendToolbarCommandId]: Not able to send CommandID=[" & $iCallersCommandID & "].", $gbDisplayMessage, $gbTerminateOnFailure)
 EndIf
 ;$giSubFunctionCounter -= 1
 Return $bContinue
EndFunc   ;==>WGe_SendToolbarCommandId
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I made a small name correction to what I said earlier.

Have you used MsgBoxes throughout during your testing, to be totally sure at what stage the process hangs?

Sometimes a Window Title can be ambiguous for a number of reasons -->

(1) You may have named your script title or folder title too closely named to the window title you are trying to detect.

(2) There may be an ASCII character in the Window Title that is not visible.

That last shouldn't be an issue if your second portion runs ok as you have suggested.

If both portions of code run right through fine when you manually execute them individually, then perhaps a judiciously placed Sleep may help?

If the full code definitely executes all the way to the WinWait command, immediately before which a Sleep might help, then it can only be a Window Title or ownership issue. As suggested, using the Window Info Tool and the appropriate Match mode should help determine this.

EDIT

Another way to help test this, is to spawn another executable for your second portion of code, so that you maintain independence. To do this, compile your second portion of code from the WinWait command, as another exe, then place the run command for it, at the beginning of your first portion of code, so that the WinWait code is up and running independently before anything else happens ... making sure you give it a timeout of a suitable length plus some. This should help you narrow down things.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Thanx for all your suggestions, i know it's not a folder issue because i don't have a name on any folder even close to that window title and i'm running the script from desktop, the matchmode setting seems interesting, ill play with that one and see if that works, can't get into work today so will hopefully try it tomorrow, i didn't think that waiting for a window was going to be this complicated :)

Link to comment
Share on other sites

This worked for now:

#include <IE.au3>
#include <File.au3>
#include <Misc.au3>
#include <Excel.au3>
$g_szVersion = "blob"
If WinExists($g_szVersion) Then Exit ; do NOT run me again!
AutoItWinSetTitle($g_szVersion)
Global $kampanj
Global $rownr
Global $oIE
Global $oFrame
Global $ClipboardData
Run(@DesktopDir & "winexists.exe")
$rownr = 1
$oIE = _IEAttach("GSM-AHS")
WinActivate("GSM")
Sleep(50)
$kampanj = "KAM02370"
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.LIST.value = $kampanj
Sleep(5000)
$oFrame = _IEFrameGetCollection($oIE, 2)
$ClipboardData = _IEPropertyGet($oFrame, "outerhtml")
If StringInStr($ClipboardData, "selected value=KAM02370") Then
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.AddButton.disabled = False
sleep(1000)
$oIE.document.all.data.contentwindow.document.forms.CampaignForm.AddButton.click
EndIf
If ProcessExists("winexists.exe") Then
ProcessWaitClose("winexists.exe")
EndIf
Exit

The code for winexists:

WinWait("Kampanj -- Webpage Dialog", "")
WinActivate("Kampanj -- Webpage Dialog", "")
Send("{ALTDOWN}s")
Sleep(100)
Send("{ALTUP}")
Sleep(100)
Send("{ALTDOWN}t")
Sleep(100)
Send("{ALTUP}")
Sleep(100)
Exit

This is the info i get from autoit window info tool:

>>>> Window <<<<

Title: Kampanj -- Webpage Dialog

Class: Internet Explorer_TridentDlgFrame

Position: 363, 234

Size: 646, 325

Style: 0x96C80000

ExStyle: 0x00000101

Handle: 0x002E0C88

>>>> Control <<<<

Class: Internet Explorer_Server

Instance: 1

ClassnameNN: Internet Explorer_Server1

Name:

Advanced (Class): [CLASS:Internet Explorer_Server; INSTANCE:1]

ID:

Text:

Position: 0, 0

Size: 640, 300

ControlClick Coords: 341, 63

Style: 0x56000000

ExStyle: 0x00000000

Handle: 0x000D0BEC

>>>> Mouse <<<<

Position: 707, 319

Cursor ID: 0

Color: 0xE0E0E0

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

>>>> Hidden Text <<<<

And also i tried to run the winexists exe at the end of this script and it failed, only if i execute it in the beginning like TheSaint suggested it works

Edited by smellyfingers
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

×
×
  • Create New...