Sign in to follow this  
Followers 0
Ziggyny

Exception Handling In _IEBodyReadText

5 posts in this topic

I've been playing around with the IE.au3 functions in an attempt to learn how to use AutoIT to script some webpage navigation. I've written a rudimentary FSM that checks to see what state the webpage is in by calling _IEBodyReadText() at the start of an infinite loop. It then uses StringInStr() to search for unique identifiers in the text returned from _IEBodyReadText(). Everything works perfectly, with one minor error...

If the IE browser is currently changing pages when I call _IEBodyReadText() the script aborts. The function doesn't return with the @error flag set, it just terminates my script.

I'm relatively new to AutoIT, so I'm wondering if this is a matter of an exception being tossed in _IEBodyReadText() because the browser doesn't have a body when the function is called? If so, is there any way in AutoIT to catch this exception to prevent the entire script from terminating?

As far as why this is coming up, I'm attempting to script the usage of a website that does searching in a database of somesort somewhere that I don't have access. All I can use is the website front-end. You submit data on the first page and then it goes to a second page that is just a 'loading' screen. After somewhere between 3 seconds to a minute the 'loading' screen disappears and a page with the results comes up. My script loops while it's on the loading page, sleeping for 500ms if it's still on the loading page. The problem arises when the script calls _IEBodyReadText() as the webpage is in transition from the loading page to the results page. As a jury-rigged fix I can have it sleep for a minute each time to guarantee it's never called while the weboage is in transition but that will really slow things down.

Any advice on how to stop the script from just terminating in the _IEBodyReadText() function?

Share this post


Link to post
Share on other sites



Adding an IE error handler, see the help file for _IEErrorHandlerRegister will stop your script from terminating on _IEBodyReadText() error.

Share this post


Link to post
Share on other sites

If it helps, the output window in AutoIT has the following output when the script teminates...

C:\Program Files\AutoIt3\Include\IE.au3 (2143) : ==> Variable must be of type "Object".:

Return $o_object.document.body.innerText

Return $o_object.document.body^ ERROR

->20:50:02 AutoIT3.exe ended.rc:1

+>20:50:03 AutoIt3Wrapper Finished

>Exit code: 1 Time: 40.844

Looking into the IE.au3 file I see that it tests to see if the object passed in is actually an object, and it tests to see if the object passed in is actually a browserdom, but it never checks to see if the browser object has a document or if that document has a body.

Share this post


Link to post
Share on other sites

Excellent, I will look into that!

As a quick fix I've started calling _IELoadWait() before calling _IEBodyReadText() and it's worked so far, but an actual error handler would be much better, thanks.

Share this post


Link to post
Share on other sites

The IEerror handler thingy worked perfectly, thanks a lot.

Share this post


Link to post
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
Sign in to follow this  
Followers 0