Sign in to follow this  
Followers 0
JayFran

Need help!! Been working on this for about a week now!

3 posts in this topic

In my code the Sleep command times out early or to late causing my exe to crash. I want a way to basically pause the code until either an object or variable is found or finished loading or no longer on the current IE page and then continue with the rest of the code. I tried using IELoadWait but that doesn't seem to be working

Share this post


Link to post
Share on other sites



Sleep won't wait for an action or event to occur, it just pauses the script for however long you set the time to. You need to set up a loop that will cycle until you find what it is you're looking for, or a set amount of time has elapsed and then exit the loop if it finds it, or doesn't. Look at While..Wend or If...then and ExitLoop.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Sleep won't wait for an action or event to occur, it just pauses the script for however long you set the time to. You need to set up a loop that will cycle until you find what it is you're looking for, or a set amount of time has elapsed and then exit the loop if it finds it, or doesn't. Look at While..Wend or If...then and ExitLoop.

Is it possible to use a While/Wend inside of an existing loop. Im only have timing issues with 2 parts of my code. Heres a snippet.

$changetab = "Change"
$c_links = _IELinkGetCollection($oIE)
For $c_link in $c_links
    $cLinkText = _IEPropertyGet($c_link, "innerText")
    If StringInStr($cLinkText, $changetab) Then
        _IEAction($c_link, "click")
        ExitLoop
    EndIf
Next
_IELoadWait($oIE, 5000)
_IELoadWait($c_Link, 5000)
; =================================================================================================
;                                           #Ticket Upload# 
; =================================================================================================
<----------------Script Error---------------->
Sleep(15000)
_IEAttach("Attachments", "html")
Sleep(1000)
$u_imageid0 = "mx847"
$u_imageid1 = "mx853"
$u_imageid2 = "Attachments"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerhtml")
    If StringInStr($sLinkText, $u_imageid0) Then
        _IEAction($oLink, "click")
          ExitLoop
    EndIf
     If StringInStr($sLinkText, $u_imageid1) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
    $uimg = _IEImgGetCollection($oIE)
        If $uimg = $u_imageid2 Then $oLink = $u_imageid2
        _IEImgClick($oIE, $u_imageid2, "alt", 0)
            ExitLoop
            
Next

Sleep(550)

So where I put the "Script error" in the code it will crash sometimes. I say sometimes because of the timing issue. Should rewrite it to sometime like:

; =================================================================================================
;                                           #ISM Ticket Field Fill & Lookup# 
; =================================================================================================
;Insert Ticket info
WinWait("Changes - Windows Internet Explorer")
Sleep(2000)
While ;<---------------------While Statement--------------->
$ticketfill = _IETagNameGetCollection($oIE, "input")
$tid_0 = "mx398"
$tid_1 = "mx404"
For $Oticketfill In $ticketfill
Global $t_post = _IEPropertyGet($oIE, "innerhtml")
If $t_post = $tid_0 Then $Oticketfill = $tid_0
If $t_post = $tid_1 Then $0ticketfill = $tid_1
Next
$t_submit = _IEGetObjById($oIE, $t_post)
_IEAction($t_submit, "focus")
Send($t_number)
Sleep(700)
Send("{Enter}")
Sleep(3500)


$changetab = "Change"
$c_links = _IELinkGetCollection($oIE)
For $c_link in $c_links
    $cLinkText = _IEPropertyGet($c_link, "innerText")
    If StringInStr($cLinkText, $changetab) Then
        _IEAction($c_link, "click")
        ExitLoop
    EndIf
Next
_IELoadWait($oIE, 5000)
_IELoadWait($c_Link, 5000)
; =================================================================================================
;                                           #Ticket Upload# 
; =================================================================================================

Sleep(15000)
_IEAttach("Attachments", "html")
Sleep(1000)
$u_imageid0 = "mx847"
$u_imageid1 = "mx853"
$u_imageid2 = "Attachments"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerhtml")
    If StringInStr($sLinkText, $u_imageid0) Then
        _IEAction($oLink, "click")
          ExitLoop
    EndIf
     If StringInStr($sLinkText, $u_imageid1) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
    $uimg = _IEImgGetCollection($oIE)
        If $uimg = $u_imageid2 Then $oLink = $u_imageid2
        _IEImgClick($oIE, $u_imageid2, "alt", 0)
            ExitLoop
            
Next

Sleep(550)

$add_new_attach = "addnew_middle_anchor"
$a_n_a = _IEGetObjById($oIE, $add_new_attach)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($a_n_a, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
$add_file = "addnewfile_middle_anchor"
$a_f = _IEGetObjById($oIE, $add_file)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($a_f, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;$pause = _IELoadWait($oIE)
Sleep(9000)

; =================================================================================================
;                                           #Iframe Window# 
; =================================================================================================

$oFrames = _IEFrameGetCollection ($oIE, 0)
$browse = _IETagNameGetCollection($oFrames, "input")
For $oBrowse In $browse
    $b_prop = _IEPropertyGet($obrowse, "innerhtml")
    If $b_prop = "file" Then $hit = $oBrowse
    Next
$b_open = _IEAction($oBrowse, "focus") ;can use click too to open the browse
Send("\\Phlh72600\techshare$\InventoryForm\C"&$t_number&".doc")
Sleep(1500)
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
WEnd ;<---------------------WEnd Statement--------------->
;_IELoadWait($oBrowse)
Sleep(12000)

; =================================================================================================
;                                           #Wrapping up# 
; =================================================================================================
While ;<---------------------While Statement--------------->
$plantab0 = "Plans"
$plantab1 = "mx209_anchor"
$p_links = _IELinkGetCollection($oIE)
For $p_link in $p_links
    $pLinkText = _IEPropertyGet($p_link, "innerText")
        If StringInStr($pLinkText, $plantab0) Then
        _IEAction($p_link, "click")
        ExitLoop
    EndIf
    $pLinkstr = _IEGetObjById($p_link, $plantab1)
    If $pLinkstr = $plantab1 Then $p_link = $plantab1
    
Next
_IEAction($p_link, "focus")
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
WEnd ;<---------------------WEnd Statement--------------->
Sleep(4500)

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