Jump to content

_IELoadWait() / Sleep()


Recommended Posts

Hello,

I have this simple script which automates google translate.

#include <IE.au3>
$oIE = _IECreate("http://translate.google.com/#en|fr|")
$oForm = _IEFormGetObjByName($oIE, "text_form")
$oText = _IEFormElementGetObjByName($oForm, "text")
_IEFormElementSetValue($oText, "Hello")
Sleep(3000)
$id = _IEGetObjById($oIE, "result_box")
$oText1 = _IEPropertyGet($id, "innertext")
MsgBox(0,"Translate",$oText1)

What i want to do it to remove the Sleep(3000) that there is in the script. But removing it the script doesnt works because the message box appears before geting the value of the innertext....

Is there a way to remove or replace the sleep time??? I tried _IELoadWait() but it doesnt work.

Any tips??

Edit: Testing for the $oText1.value just add some more pointless lines to the script and leeds at adding sleep seconds until value is true...

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Hello,

I have this simple script which automates google translate.

#include <IE.au3>
$oIE = _IECreate("http://translate.google.com/#en|fr|")
$oForm = _IEFormGetObjByName($oIE, "text_form")
$oText = _IEFormElementGetObjByName($oForm, "text")
_IEFormElementSetValue($oText, "Hello")
Sleep(3000)
$id = _IEGetObjById($oIE, "result_box")
$oText1 = _IEPropertyGet($id, "innertext")
MsgBox(0,"Translate",$oText1)

What i want to do it to remove the Sleep(3000) that there is in the script. But removing it the script doesnt works because the message box appears before geting the value of the innertext....

Is there a way to remove or replace the sleep time??? I tried _IELoadWait() but it doesnt work.

Any tips??

Edit: Testing for the $oText1.value just add some more pointless lines to the script and leeds at adding sleep seconds until value is true...

I think you need to rethink whether "pointless lines to the script" is what that really is, if it helps you achieve your goal

I'd say what might be pointless is developing an ulcer over a couple of lines of code.

_IELoadWait is not reliable I have found, the event fires multiple times during a page load, and that is down to IE and

not the UDF.

Loop a test for a value returned in these lines of code.

$id = _IEGetObjById($oIE, "result_box")

$oText1 = _IEPropertyGet($id, "innertext")

Or perhaps just the latter, no-one is forcing you to sleep seconds in the loop it could be 100 ms

and be ready when it's ready.

Add i timeout in the loop.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This is not my script my friend. This is a simplified example for people to understand,run and test it...I find that not hard to understand.

I know that _IELoadWait() is not reliable that's why i am asking if there is another way.

And as i already said looping through it would just add seconds until it is ready.Which means pointless lines since the resault would be the same.Then why not simply use sleep()?It is 1 single line with not much in-it. The translation and combinatios of all languages is 40*40*9. It's 18000 lines script(Most of it repeating lines with small changes) so it would be 2000 lines extra for the same resault... That's why its pointless...

Anyway i am asking if there is an other command to do the job that _IELoadWait() should do and be reliable.

I feel nothing.It feels great.

Link to comment
Share on other sites

Why not put the repeating lines into a function and pass the parameters, that change, to it instead of redoing them over and over?

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

Link to comment
Share on other sites

Your statements that _IELoadWait is unreliable are idiodic. The fact is that you don't understand how it works and you wish it worked the way you want it to - that is unreliable.

_IELoadWait checks the "readyState" property of a document or an element - if it is "complete", it returns success, if it returns any other state, it loops waiting for to be "complete".

The most efficient way of doing what you wnat here is to set up an event handler for the "result_box" element that fires on an "onchange" event and returns the value you are seeking from the element. See ObjEvent().

Update: I see that "result_box" is a SPAN and not an INPUT element, so it has no onchange event. You'll need to poll for changes in innertext as suggested by John.

Dale

Edited by DaleHohm

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

Then why it doesnt work??? I have tried putting it between all the lines. I have tried adding more than one... Since i add _IELoadWait() at the script why it sets the data of the edit before even loading the navigate???

I feel nothing.It feels great.

Link to comment
Share on other sites

You're a lost cause.

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

Other people read these posts for reference. Stop stating that something doesn't work when the problem is that you don't understand it.

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

I did explain it, John gave you a solution and I confirmed it... There is no Navigate occuring, the document readyState is always Complete, so _IELoadWait can never so what you want it to do. It works the way it works, not the magical way you want it to. Read what John suggested again - that is your solution.

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

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

×
×
  • Create New...