Sign in to follow this  
Followers 0
smellyfingers

WinWait problem?

20 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
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 :/

Share this post


Link to post
Share on other sites

Hi JohnOne, Yes i can see it, also shows in autoit window info tool

Share this post


Link to post
Share on other sites

Hey,

What I find useful for WinWait() is to use AutoItSetOption("WinTitleMatchMode", 2) at the beginning of the script.

Then, change your WinWait() to WinWait("Kampanj")

That should make your life easier :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Ok but if the popup is never modal when manually clicking the addbutton since the first script never fails how can it be modal when autoit is doing the click?, i'm confused :), ill look into cmd line parameters, ty

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

Cool, ty ill play with that next time im at work, i also need to set 2 dates in 2 cell within a table in the popup based on the $kampanj variable, but that's another problem i need to work on after solving this :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

So when this is called

$oIE = _IEAttach("GSM-AHS")

Does the handle of that window then belong to Autoit? and subsequent child windows?

I was gonna say yes, but i'm not sure how to test if that's true Edited by smellyfingers

Share this post


Link to post
Share on other sites

If the popup gets activated from winactivate($oIE) then it should be true i guess and i think it does, gonna have to try it at work tho

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

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

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

  • Similar Content

    • ur
      By ur
      if ControlClick("[CLASS:MsiDialogCloseClass]"," ","[CLASS:SysTreeView32; INSTANCE:1]") Then $htreeview=ControlGetHandle($hwnd,"","[CLASS:SysTreeView32; INSTANCE:1]") ControlTreeView($hwnd," ",$htreeview,"Select","#4") The above code worked well to enable the martupgrade feature on windows 7.
      As part of our Installation Testing Automation before delivering the installer to end user.To confirm whether all the screens are working good.

      But it is not working on windows 10.
       
      $h= ControlTreeView($hwnd," ",$htreeview,"Select","#4") The $h is getting value 1,which means error.
    • ur
      By ur
      I have automated an install process by using the below code.
       
      Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc $win1 = "Text 1" $win2 = "Text 2" _WinWaitActivate($win1,"WARNING: This progra") Send("{ALTDOWN}n{ALTUP}");Send("{SPACE}") _WinWaitActivate($win1,"I DISAGREE and &do n") Send("{UP}n") _WinWaitActivate($win1,"Customer Information") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}{TAB}n") _WinWaitActivate($win1,"Click Next to instal") Send("{ALTDOWN}n{ALTUP}");Send("n") _WinWaitActivate($win1,"This feature require") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}n") _WinWaitActivate($win1,"Ready to Install the") Send("{ALTDOWN}i{ALTUP}");Send("i") _WinWaitActivate($win1,"The InstallShield Wi") Send("{ALTDOWN}f{ALTUP}");Send("f") _WinWaitActivate($win2,"You must restart you") Send("{ALTDOWN}n{ALTUP}");Send("n") Now if any new screen comes in the middle of installation, like some VC++ installation error or like that.
      The AutoIT is waiting in the background.
      Is there any way to skip the new screens with just "enter" and continue the installation??
    • TheInfamousOne
      By TheInfamousOne
      I have a small exe I created in AutoIt that seems to be causing some problems in OutLook when people go to save a PDF or Reply to emails.

      Here is my code.
       
      TraySetState(2) WinWait("[CLASS:#32770]", "Make sure that your sign-in address, user name, and password are correct and try again.", 0) WinClose( "Lync")  
      So this works just fine, it closes these message prompts we are trying to suppress.  But if the autoit executable is running when someone is using Outlook and they go to Save as PDF.  When they click "Save As" and go to type in the name of the file to save, they can't type in the box.  So if they close the autoit executable that's running only the code above, then they can use type in the name of the file.  So we know the EXE is preventing users from saving documents.

      Now, I'm sure it could be the way I've written this code, but I'm new to AutoIt and I'm not sure what could be causing this.  This little script seems like it' targeting the correct CLASS # and Window TItle and exact message.  So I don't understand why it's interfering with other applications.

      Any ideas?
    • feelie75
      By feelie75
      Hi. i googled and searched a lot before posting this. thanks for any help.
      I need to locate a window that has no title or discernible text, BUT is always the same size. The autoit documentation says:
      "X \ Y \ W \ H - The position and size of a window
      One or more properties are used in the title parameter of a window command in the format:
      [PROPERTY1 : Value1; PROPERTY2:Value2]"
      However, i can't figure out exactly how to do that. i tried:
      Local $winAW = WinWait("[W:506;H:288]", "", 30);
      That didn't work. I couldn't find an example of the specific format I need to use. Can someone provide a proven working example? Maybe that example can be added to the documentation? Thanks!
    • DeeJay7
      By DeeJay7
      I'm looking possible ways to optimize sleep time in a script which has multiple sleep times for save, refresh etc.
      The sleep duration varies from 5 secs to 17 secs time to time (depending upon the record, computer performance etc).
      Currently I set max sleep duration. ie sleep(17000).
      I'm looking possible ways to dynamically change sleep duration rather than fixed maximum duration.
      Note: winwait is not helpful in my script.
      Thanks in advance for your responses