Automating Internet Explorer (Intermediate)

We'll now have a look at the collection of functions for creating, attaching to, reading from, and manipulating Internet Explorer. Internet Explorer automation functions start as _IExxx.

Getting ready

Open SciTE from the AutoIt Program Group and start writing source code.

We can optionally update a few features to improve results:

How to do it...

The following are two examples of interaction with Internet Explorer:

  • Navigate and click on links:
    #include <IE.au3> 
    $o_IE = _IECreate () 
    _IENavigate ($o_IE, "http://autoitscript.com") 
    MsgBox(0,"IE.au3 Test","Enter for next Internet Explorer command: Click text Forum ") 
    _IELinkClickByText ($o_IE, "Forum") 
    MsgBox(0,"IE.au3 Test","Enter for next Internet Explorer command: Click text Wiki") 
    _IELinkClickByText ($o_IE, "Wiki") 
  • Search a text string and modify a web page on-the-fly:
    #include <IE.au3> 
    $oIE = _IECreate() 
    _IENavigate($oIE, "http://www.autoitscript.com/") 
    $body = _IEBodyReadHTML($oIE) 
    If StringInStr($body, "autoit") Then 
    MsgBox(0, "Success", "The string was found. Press enter to modify web page") 
    $newbody = StringReplace($body, "autoit", "AUTOMATION: YOUR NAME HERE, XXX!")
     _IEBodyWriteHTML($oIE, $newbody) 
    Else 
    MsgBox(0, "Fail", "The string was NOT found") 
    EndIf 
    How to do it...

How it works...

_IExxx functions work for Internet Explorer (IE) automation. You create a navigation object with _IENavigate for a web page, and then send commands, for example, click on links. You can also try using _IEAction($object, "many actions E.G. click").

_IEbodyWriteHTML() writes HTML into an active page object.

For more on this, visit http://www.youtube.com/watch?v=1TVf2xZDdfE.

There's more...

Let us look at two more subjects. The first one is about getting Internet Explorer values and IDs to manage them later in any AutoIt script. The second one is about how to automate Firefox using an external Firefox automation tool (iMacros), and how to get this working inside our AutoIt applications.

Identifying Internet Explorer objects

Extra tools, _IExxx functions parameters, and debug Scripts can be obtained from the following links:

Using iMacros and AutoIt for Firefox automation.

Firefox Portable automation is possible by creating an iMacros script, and running it within AutoIt.

You can download Firefox Portable from http://portableapps.com/apps/internet/firefox_portable and iMacros from https://addons.mozilla.org/es/firefox/addon/imacros-for-firefox/, and then install them.

Then, you can create an AutoIt script to run any previously stored iMacros as:

Run("FirefoxPortable.exe imacros://run/?m=WP-backup.iim") 

Wp-backup.iim imacro should be created using the iMacros interface. You can modify iMacros behavior on-the-fly (reading, writing, and running this template iMacros script file).

A working AutoIt iMacros template can be downloaded here:

http://www.emesn.com/autodownloads/wp-automatic-backup.php

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset