Jump to content

While Loop Help


Recommended Posts

guys im not good with while loops at all. what i need is a while loop that checks the title of the active window until a certain title is reached then it continues the script. only prob is i need it to check for 2 different titles.

lets say the script navigates to a website, then it checks the title with wingettitle("",""), the title of the IE window is "about:blank" so the website is still loading. well i need it to keep checking the title until the title reads different, if the title reads "the page cannot be displayed" i need it to browse to another website and if the title reads "Connect to infocenter" i need it to run the rest of the script?

i tried to use an if then but i dont know how to make it loop through.

any help would be great.

Link to comment
Share on other sites

guys im not good with while loops at all. what i need is a while loop that checks the title of the active window until a certain title is reached then it continues the script. only prob is i need it to check for 2 different titles.

lets say the script navigates to a website, then it checks the title with wingettitle("",""), the title of the IE window is "about:blank" so the website is still loading. well i need it to keep checking the title until the title reads different, if the title reads "the page cannot be displayed" i need it to browse to another website and if the title reads "Connect to infocenter" i need it to run the rest of the script?

i tried to use an if then but i dont know how to make it loop through.

any help would be great.

i'd say to use IE.au3 for that situation. it has _IELoadWait() that pauses execution until the browser is done loading the page.
Link to comment
Share on other sites

yea i know but im having to set _IENavigate ($oIE, $url, 0)

because if i get a "connect to infocenter" title. that is a popup dialog for login and password and to the ie.au3 it is still loading

so if i leave it set to wait for IE to load it never goes to the next step of the script because its waiting on input from the user for login and pass

Link to comment
Share on other sites

  • Moderators

Something like this should work:

While 1
    $a = WinExists("the page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then
    ;Browse to different page
        ExitLoop
    ElseIf $b == 1 Then
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd
Link to comment
Share on other sites

Something like this should work:

While 1
    $a = WinExists("the page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then
;Browse to different page
        ExitLoop
    ElseIf $b == 1 Then
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd
with the loadwait in the ienavigate() function, i don't think that will work if IE.au3 is being used. my suggestion would be either to add that code from big_daddy, and comment out the loadwait in ie.au3 but throw a load wait after that segment. so after entering login info, the script will wait for the page to load. i don't typically reccomend altering well written udf's like ie.au3 though so what i would say to do is implement a multi threaded approach. you could make a script just for processing the credentials window, and fileinstall it into your current script, then run it before navigating to the page, if it's got a while loop that exits after the window is processed, then even though the main script is sleeping in the loadwait() from ie.au3, the other script will make it so that isn't a permanent condition, and the browser DOES finish loading.
Link to comment
Share on other sites

here is the load wait for the IE.au3... ( the old one may still be in the UDF )

Func _IELoadWait($o_object, $i_delay = 0)
    If IsObj($o_object) Then
        Sleep($i_delay)
        If ObjName($o_object) = "IWebBrowser2" Then
            While _IEGetProperty($o_object, "busy") or _
                ((_IEGetProperty($o_object, "readyState") <> "complete") and _
                 (_IEGetProperty($o_object, "readyState") <> 4))
                Sleep(100)
            WEnd
        EndIf
        While ($o_object.document.readyState <> "complete") and _
            ($o_object.document.readyState <> 4)
            Sleep(100)
        WEnd
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc;==>_IELoadWait

EDIT:.... just checked and the old load wait is still there

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Ok I got it working :think:

While 1
    $a = WinExists("the page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then
;Browse to different page
        ExitLoop
    ElseIf $b == 1 Then
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd

I tried this code but as soon as the page loads all the way the script exits?

here is my complete script

#include <ie.au3>
Opt("TrayIconDebug", 1)
; User Variable's
Dim $oIE
$FFLOGIN = "username"
$FFPASS = "pass"
$sUrl = "https://website.com"
$cUrl = "https://website2.com"

_IEAttach ($oIE)
If Not IsObj($oIE) Then
    $oIE = _IECreate ()
    _IENavigate ($oIE, $sUrl, 0)
EndIf

While 1
    $a = WinExists("the page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then 
                _IENaviage($oIE, $cUrl)
        ExitLoop
    ElseIf $b == 1 Then
        _SendLogin()
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd



Func _SendLogin()
    WinWaitActive( "Connect to infocenter", "")
    WinActivate( "Connect to infocenter", "")
    ControlSetText( "Connect to infocenter", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to infocenter", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to infocenter", "", "Button2" )
EndFunc
Edited by anyday
Link to comment
Share on other sites

maybe

#include <ie.au3>
Opt("TrayIconDebug", 1)
; User Variable's
Dim $oIE
$FFLOGIN = "username"
$FFPASS = "pass"
$sUrl = "https://website.com"
$cUrl = "https://website2.com"

_IEAttach ($oIE)
If Not IsObj($oIE) Then
    $oIE = _IECreate ()
    _IENavigate ($oIE, $sUrl, 0)
EndIf

While WinExists("Connect to infocenter") <> 1
    
    If WinExists("the page cannot be displayed") Then  _IENavigate ($oIE, $cUrl, 0)
    
WEnd

 _SendLogin()


Func _SendLogin()
    WinWaitActive( "Connect to infocenter", "")
    WinActivate( "Connect to infocenter", "")
    ControlSetText( "Connect to infocenter", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to infocenter", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to infocenter", "", "Button2" )
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

hey guys is there any way to make the script start over once it finds a match to $a = WinExists("The page cannot be displayed").

what i need is for when the

$a = WinExists("The page cannot be displayed") is found it runs a function i created but after that function i need the script to start over?

Link to comment
Share on other sites

hey guys is there any way to make the script start over once it finds a match to $a = WinExists("The page cannot be displayed").

what i need is for when the

$a = WinExists("The page cannot be displayed") is found it runs a function i created but after that function i need the script to start over?

post your code so far... then we can try to help

8)

NEWHeader1.png

Link to comment
Share on other sites

ok here goes :think:

#include <ie.au3>
Opt("TrayIconDebug", 1)
; User Variable's
Dim $oIE
$FFLOGIN = "user"
$FFPASS = "pass"
$sUrl = "https://website.com"
$cUrl = "https://website2.com"

_IEAttach ($oIE)
If Not IsObj($oIE) Then
    $oIE = _IECreate ()
    _IENavigate ($oIE, $sUrl, 0)
EndIf

While 1
    $a = WinExists("The page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then
        _IENavigate($oIE, $cUrl, 0)
        _SendLoginEnroll()
        ExitLoop
    ElseIf $b == 1 Then
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd
While 1
    Sleep(2000)
WEnd

Func _SendLogin()
    WinWaitActive( "Connect to infocenter", "")
    WinActivate( "Connect to infocenter", "")
    ControlSetText( "Connect to infocenter", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to infocenter", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to infocenter", "", "Button2" )
EndFunc

Func _SendLoginEnroll()
    WinWaitActive( "Connect to enroll", "" )
    WinActivate( "Connect to enroll", "" )
    ControlSetText( "Connect to enroll", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to enroll", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to enroll", "", "Button2" )
        <----> Future script here and then after all the script here i need it to restart the script!!!!!!!
EndFunc

what the deal is the 1st website i goto requires a certificate installed to browse it and if the cert is not installed it dump's you to the page cannot be displayed screen, well when a user gets the page cannot be displayed it browses to another website and install's the cert. so after that happens i need the script to browse back to the original URL which will now give the script the $b = WinExists("Connect to infocenter") prompt.

Link to comment
Share on other sites

  • Moderators

You shouldn't need to restart the whole script, try this:

#include <ie.au3>
Opt("TrayIconDebug", 1)
; User Variable's
Dim $oIE
$FFLOGIN = "user"
$FFPASS = "pass"
$sUrl = "https://website.com"
$cUrl = "https://website2.com"

_IEAttach ($oIE)
If Not IsObj($oIE) Then
    $oIE = _IECreate ()
    _IENavigate ($oIE, $sUrl, 0)
EndIf

_CheckWebpage()
_SendLogin()


Func _CheckWebpage()
    
    While 1
    $a = WinExists("The page cannot be displayed")
    $b = WinExists("Connect to infocenter")
    If $a == 1 Then
        _IENavigate($oIE, $cUrl, 0)
        _SendLoginEnroll()
        _IENavigate ($oIE, $sUrl, 0)
        ExitLoop
    ElseIf $b == 1 Then
        ExitLoop
    Else
        Sleep(100)  
    EndIf
WEnd

EndFunc

Func _SendLogin()
    
    WinWaitActive( "Connect to infocenter", "")
    WinActivate( "Connect to infocenter", "")
    ControlSetText( "Connect to infocenter", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to infocenter", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to infocenter", "", "Button2" )
    
EndFunc

Func _SendLoginEnroll()
    
    WinWaitActive( "Connect to enroll", "" )
    WinActivate( "Connect to enroll", "" )
    ControlSetText( "Connect to enroll", "", "Edit2", $FFLOGIN )
    ControlSetText( "Connect to enroll", "", "Edit3", $FFPASS )
    ControlClick ( "Connect to enroll", "", "Button2" )
      ; <----> Future script here and then after all the script here i need it to restart the script!!!!!!!
        
EndFunc
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...