Jump to content

Wait for IE to finish loading


Recommended Posts

The problem that I have is _IEGetObjById($oIE, "dditd") comes up empty because the page is not finished loading in time. If the addresses are all from the same state this code works fine but if I skip from state to state the page takes a long time to load. I added Sleep but it just isn't working and _IELoadWait($oIE) does not work in this case either.

CODE
$1add = GUICtrlRead($txt1Add)

$1city = GUICtrlRead($txt1city)

$1state = GUICtrlRead($txt1state)

$2add = GUICtrlRead($txt2Add)

$2city = GUICtrlRead($txt2city)

$2state = GUICtrlRead($txt2state)

$3add = GUICtrlRead($txt3Add)

$3city = GUICtrlRead($txt3city)

$3state = GUICtrlRead($txt3state)

$4add = GUICtrlRead($txt4Add)

$4city = GUICtrlRead($txt4city)

$4state = GUICtrlRead($txt4state)

$5add = GUICtrlRead($txt5Add)

$5city = GUICtrlRead($txt5city)

$5state = GUICtrlRead($txt5state)

$6add = GUICtrlRead($txt6Add)

$6city = GUICtrlRead($txt6city)

$6state = GUICtrlRead($txt6state)

$1address = "from: " & $1add & "," & $1city & " " & $1state

$2address = " to: " & $2add & "," & $2city & " " & $2state

$3address = " to: " & $3add & "," & $3city & " " & $4state

$4address = " to: " & $4add & "," & $4city & " " & $4state

$5address = " to: " & $5add & "," & $5city & " " & $5state

$6address = " to: " & $6add & "," & $6city & " " & $6state

If $1city = "" or $1state = "" then $1address = ""

If $2city = "" or $2state = "" then $2address = ""

If $3city = "" or $3state = "" then $3address = ""

If $4city = "" or $4state = "" then $4address = ""

If $5city = "" or $5state = "" then $5address = ""

If $6city = "" or $6state = "" then $6address = ""

$addresses = $1address & $2address & $3address & $4address & $5address & $6address

If $1address > "" and $2address > "" Then

$TotalMileageandTT = MileageTotal($addresses)

GUICtrlSetData($lbltotal,$TotalMileageandTT)

EndIf

Func MileageTotal($addresses)

$sUrl = "http://maps.google.com"

$oIE = _IECreate($sUrl,0,0)

$oForm = _IEFormGetObjByName($oIE, "q_form")

$oInput = _IEFormElementGetObjByName($oForm, "q")

_IEFormElementSetValue($oInput, $addresses)

_IEFormSubmit($oForm)

Sleep(1000)

$oDiv = _IEGetObjById($oIE, "dditd")

If @error = 7 Then

Sleep(4000)

$oDiv = _IEGetObjById($oIE, "dditd")

If @error = 7 Then

Sleep(5000)

$oDiv = _IEGetObjById($oIE, "dditd")

EndIf

EndIf

$Result = (_IEPropertyGet($oDiv, "innertext"))

If $Result = "" Then

MsgBox(0, "Mileage Calculation Error", "Total Mileage and Total Travel Time" & @CRLF & "Error")

Else

$data = StringSplit($Result,"")

$data1 = StringTrimRight($data[1],1)

$data2 = StringTrimLeft($data[2],7)

$data2 = StringTrimRight($data2,1)

$MileageandTime = ($data1 & "les" & @CRLF & $data2 & "utes")

EndIf

Return $MileageandTime

_IEQuit ($oIE)

EndFunc

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Link to comment
Share on other sites

You can change the sleep to a loop until dditd is of object type:

Sleep(1000)
$oDiv = _IEGetObjById($oIE, "dditd")
If @error = 7 Then
    Sleep(4000)
    $oDiv = _IEGetObjById($oIE, "dditd")
    If @error = 7 Then
        Sleep(5000)
        $oDiv = _IEGetObjById($oIE, "dditd")
    EndIf
EndIfoÝ÷ Ù·¢gºÚ"µÍÚ[HÝÓØÒQQÙ]ØRY
    ÌÍÛÒQK  ÌÎNÙ]    ÌÎNÊJBTÛY
L
BÑ[
Link to comment
Share on other sites

You can also wait for a particular ELEMENT to load... just pass the element object reference to _IELoadWait instead of $oIE. You can also check the readyState of an arbitrary element (see _IEPropertyGet) and wait for it to be 4.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thanks guys it works great now! I figured out why it was taking sooooo long though.

CODE
$2address = " to: " & $2add & "," & $2city & " " & $2state

$3address = " to: " & $3add & "," & $3city & " " & $4state

$4address = " to: " & $4add & "," & $4city & " " & $4state

$3address = " to: " & $3add & "," & $3city & " " & $4state<-- That was supposed to be $3state

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Link to comment
Share on other sites

Thanks Authenticity & Dale

I will try those ideas, now.

I'm having simillar difficulties:

-I'm writing a BOT for travian.

- On the 1st page i open which is the main city page ( "dorf1" ) everything is working properly.

for example, I can read tables using the _IE commands.

- When i move to another city, there is another "dorf1" page, which has exactly the same structure, yet

I cannot read any of the tables using the _IETableGetCollection.

Weird, but _IEGetObjById is working properly on the same page !!

I have no clue why this is happenning.

I tried a function like the one below to wait until the IE loads the tables, however,

even after 10sec this function doen't exit, so i assume the problem is elsewhere...

( I've tries the IELoadWait( $oIE ), though did not tried it on $oTable like someone suggested here. )

Func WaitPageLoad_Tables()

$ec = 0

While $ec = 0

$ec = UBound( _IETableGetCollection( $oIE ))

Sleep(100)

WEnd

EndFunc

Thanks !!!

Shahaf

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