Jump to content

For Loop Question


Recommended Posts

#include "IE.au3"
#include "file.au3"

dim $specialCharURL = "barnes[@)noble"
dim $searchString = "barnesandnoble"

dim $log = "6539"

$oIE = _IECreate($specialCharURL, 0, 1, 1, 0)

IF @error = 0 Then
    $oLinks = _IELinkGetCollection($oIE)                        
    $iNumLinks = @extended                          
    For $oLink In $oLinks                           
       IF(StringInStr($oLink.href, $searchString) <> 0) Then                          _FileWriteLog(@ScriptDir & "\"& $log &"_passed.txt", "The special characters in '" & $specialCharURL & "' opened the search page " & $actualResolvedURL & " and have links on the search page resolved as " & $searchString)
           ExitLoop                         
                   Elseif(?????) Then
          _FileWriteLog(@ScriptDir & "\"& $log &"_FAILED.txt", "The search page didnot have any links that were resolved to " & $searchString)
       EndIf
    Next
Else
    _FileWriteLog(@ScriptDir & "\"& $log &"_FAILED.txt", "Internet Explorer could not be opened")
EndIf

_IEQuit($oIE)

In the script above, where I have put ?????, I want to figure out a way to develop and expression inside that elseif statement. What I am intending to do it, to go through all the links in the page and look for a particular search string. But if that search string is not found and all the links have been searched, I report an error.

The elseif statement should check the total number of links (that I get through $iNumLinks) against the current iteration to see if the current iteration has reached the last link and still a match is not found. How do I find the current iteration for this for loop and hence how do I write this elseif statement?

Link to comment
Share on other sites

Pulled this from the help files and made a few simple changes.

#include <IE.au3>

$Target_URL = 'www.google.com'
$Target_String = 'about.html'

$oIE = _IECreate ($Target_URL)
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended

$Link_Index = 0
$Link_Found = False

If @error = 0 Then
    For $oLink In $oLinks
        $Link_Index += 1
        If StringInStr($oLink.href,$Target_String) Then
            $Link_Found = True
            ConsoleWrite( 'Search String was found : ' & $oLink.href & @CRLF )
        ElseIf $Link_Index = $iNumLinks And $Link_Found = False Then
            ConsoleWrite( 'Search string was not found.' & @CRLF )
        EndIf
    Next
EndIf
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...