smellyfingers Posted December 11, 2012 Share Posted December 11, 2012 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: expandcollapse popup#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 More sharing options...
TheSaint Posted December 11, 2012 Share Posted December 11, 2012 (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$kampanjinstead 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.EDITDidn't have access to an AutoIt installation at the time, so I've corrected WinSetTitleMatch to WinTitleMatchMode. Edited December 12, 2012 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) Link to comment Share on other sites More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 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 More sharing options...
JohnOne Posted December 11, 2012 Share Posted December 11, 2012 Does "Kampanj -- Webpage Dialog" actually exist? you can see it? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 Hi JohnOne, Yes i can see it, also shows in autoit window info tool Link to comment Share on other sites More sharing options...
Colyn1337 Posted December 11, 2012 Share Posted December 11, 2012 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 Link to comment Share on other sites More sharing options...
JohnOne Posted December 11, 2012 Share Posted December 11, 2012 Try copying the exact title out of AUTWIFT. "AutWift" what a name. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jdelaney Posted December 11, 2012 Share Posted December 11, 2012 (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 December 11, 2012 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 More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 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 More sharing options...
jdelaney Posted December 11, 2012 Share Posted December 11, 2012 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 More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 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 Link to comment Share on other sites More sharing options...
jdelaney Posted December 11, 2012 Share Posted December 11, 2012 (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 December 11, 2012 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 More sharing options...
JohnOne Posted December 11, 2012 Share Posted December 11, 2012 So when this is called $oIE = _IEAttach("GSM-AHS") Does the handle of that window then belong to Autoit? and subsequent child windows? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 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 Link to comment Share on other sites More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 (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 December 11, 2012 by smellyfingers Link to comment Share on other sites More sharing options...
smellyfingers Posted December 11, 2012 Author Share Posted December 11, 2012 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 Link to comment Share on other sites More sharing options...
JohnOne Posted December 11, 2012 Share Posted December 11, 2012 $oIE is an object type, not a window handle (hWnd). Just wondering because It attached to the window whether it becomes owned by the process that attached to it AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
TheSaint Posted December 12, 2012 Share Posted December 12, 2012 (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.EDITAnother 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 December 12, 2012 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) Link to comment Share on other sites More sharing options...
smellyfingers Posted December 12, 2012 Author Share Posted December 12, 2012 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 More sharing options...
smellyfingers Posted December 17, 2012 Author Share Posted December 17, 2012 (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 ExitThe 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 DialogClass: Internet Explorer_TridentDlgFramePosition: 363, 234Size: 646, 325Style: 0x96C80000ExStyle: 0x00000101Handle: 0x002E0C88>>>> Control <<<<Class: Internet Explorer_ServerInstance: 1ClassnameNN: Internet Explorer_Server1Name:Advanced (Class): [CLASS:Internet Explorer_Server; INSTANCE:1]ID:Text:Position: 0, 0Size: 640, 300ControlClick Coords: 341, 63Style: 0x56000000ExStyle: 0x00000000Handle: 0x000D0BEC>>>> Mouse <<<<Position: 707, 319Cursor ID: 0Color: 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 December 17, 2012 by smellyfingers Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now