Jump to content

Loop Problem Using #ie.au3


Dubz
 Share

Recommended Posts

Hey, I hope I'm not making too many threads to cover a single script. What happens is does the beginning properly until it reaches the "Do - Until" part. It keeps repeating a single part of the loop, meaning it always sees "login". Thing is, if you look at the HTML code on the Map page, there is no word "login" to be found... So this part:

$body = _IEBodyReadHTML($o_IE)
$tester = StringInStr($body, "login")
If $tester = "login" Then
...That part seems not to be doing what I thought it would do. I want it to read the HTML of the current page in IE (which should be $o_IE), and then test for the word "login". Unless I am logged out (logs out every 30min or so), it should continue to the 'Else ' part of the script.

Here is the full script. I've also attached it. The User and Pass will work if you wish to log in and check the source of any page:

#include <IE.au3>
#include <file.au3>
#include <Array.au3>

; Set Variables
$pos1 = 1
$pos2 = 1

; Create a browser window & navigate to Inselkampf.co.uk
$o_IE = _IECreate ()
_IENavigate ($o_IE, "http://80.237.203.111/index.php?lang=en")
$o_form = _IEFormGetObjByIndex($o_IE, 0)
$o_user = _IEFormElementGetObjByName($o_form, "member")
$o_password = _IEFormElementGetObjByName($o_form, "pwd")
_IEFormElementSetValue($o_user, "Foreplay")
_IEFormElementSetValue($o_password, "521j03")
_IEFormSubmit($o_form)
_IELoadWait($o_IE)
_IEClickLinkByText ($o_IE, "Go To Your Isle »")
_IEClickLinkByText ($o_IE, "Map")

; Grabs HTML from all open ocean squares and pastes them into a txt file.
Do
$o_form = _IEFormGetObjByIndex($o_IE, 0)
$ocean = _IEFormElementGetObjByName($o_form, "pos1")
$o_square = _IEFormElementGetObjByName($o_form, "pos2")
_IEFormElementSetValue($ocean, $pos1)
_IEFormElementSetValue($o_square, $pos2)
_IEFormSubmit($o_form)
_IELoadWait($o_IE)
$body = _IEBodyReadHTML($o_IE)
$tester = StringInStr($body, "login")
If $tester = "login" Then
    _IENavigate ($o_IE, "http://80.237.203.111/index.php?lang=en")
    $o_form = _IEFormGetObjByIndex($o_IE, 0)
    $o_user = _IEFormElementGetObjByName($o_form, "member")
    $o_password = _IEFormElementGetObjByName($o_form, "pwd")
    _IEFormElementSetValue($o_user, "Foreplay")
    _IEFormElementSetValue($o_password, "521j03")
    _IEFormSubmit($o_form)
    _IELoadWait($o_IE)
    _IEClickLinkByText ($o_IE, "Go To Your Isle »")
    _IEClickLinkByText ($o_IE, "Map")
Else
    _FileCreate ("C:\Documents and Settings\Owner\My Documents\IK Tool Script\IK_file.txt")
    $file = FileOpen("IK_file.txt", 1)
    FileWrite($file, $body)

    _IEClickLinkByText ($o_IE, "Map")

    $pos2 = $pos2 + 1
    If $pos2 = 101 Then
        $pos2 = 1 
        $pos1 = $pos1 + 1
        If $pos1 = 7 Then $pos1 = 11
        If $pos1 = 16 Then $pos1 = 21
        If $pos1 = 25 Then $pos1 = 31
        If $pos1 = 34 Then $pos1 = 41
    EndIf
EndIf
Until $pos1 = 43
Link to comment
Share on other sites

Run this and see what it returns. StringInStr returns a number value for the location of the beginning of the string (if it is found), so it will never be equal to a string.

$body = _IEBodyReadHTML($o_IE)
$tester = StringInStr($body, "login")
MsgBox (0, "tester", $tester)

What you should have is:

$body = _IEBodyReadHTML($o_IE)
If StringInStr($body, "login") Then
...

Haven't looked at the rest of it, but give that a try for now.

Link to comment
Share on other sites

Your help with understanding StringInStr was just what I needed. I've replaced that line with:

$body = _IEBodyReadHTML($o_IE)
$tester = StringInStr($body, "login")

If $tester <> 0 Then

Now it works. I don't know how it will respond to being logged out though. I tried making it so that if it $tester = 0, it would skip the 'If' portion and continue the script, but it kept looping. 0 is supposed to be fail, so I think the part is still broken.

I tried what you posted, but it continued looping :think:

I'm thinking that it's reading $o_IE to have "login" somewhere... but it isn't there on the page it's supposed to be grabbing from.

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...