Jump to content
Sign in to follow this  
scriptkitty

IE Fun Part 2

Recommended Posts

scriptkitty

While testing out the new COM/OBJ functions I ran into some issues.

Basically IFrames are a problem for scripting many times. Many sites will set up thier Iframes with the wrong settings due to domain name restrictions.

Example, Hotmail.com is owned by microsoft, and it forwards the iframes to

passport.net. This is a problem scripting because IE had a problem in security and thier fix was to restrict the parent from accessing the child objects if not the same domain.

Navigating and scripting in frames can be a bit tricky, so hopefully this will aid you in your adventures.

I targeted the starting page to passport.net so that you could see that iframes are supported when done from the same url.

This is a huge restriction because even www.microsoft.com and microsoft.com are technically different (there is a document.domain setting that allows pages in the same domain to work, but has to be set on all pages and sub pages.)

I made this little gui so that you could explore sites and see the HTML of frames and Iframes. You will notice that when you are on a site that has the proper use of IFrames and Frames, you can see the main, and up to 4 child frame HTML.

Use the update button, or press the pause key to update the GUI after you change sites.

; direct access via COM 
; available in current beta version
HotKeySet("{pause}","update")
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

$ObjIE=ObjCreate("InternetExplorer.Application")

With $ObjIE
;  .Visible = True
.Navigate("http://login.passport.net")
.left=200
.top=200
.height=400
.width=800
.menubar=1
.toolbar=1
.statusBar=1
.visible=1
; usefull information
;.top = <integer>
;.left = <integer>
;.width = <integer>
;.height = <integer>
;.visible = <integer>;(1 - Visible/ 0 - Not Visible)
;.menuBar = <integer>;(1 - Visible/ 0 - Not Visible)
;.toolBar = <integer>;(1 - Visible/ 0 - Not Visible)
;.statusBar = <integer>;(1 - Visible/ 0 - Not Visible)
;.goHome; to go to home
;.document.body.innerHTML; the HTML of the page
;.document.body.innerText; the text displayed on the page
while .busy
   tooltip("loading")
   sleep(10)
WEnd
   tooltip("")
EndWith

#include <GUIConstants.au3>
Dim $edit[5]
GUICreate("My GUI edit",600,650,0,0); will create a dialog box that when displayed is centered
$myedit=GUICtrlCreateEdit ("", 0,0,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$edit[0]=GUICtrlCreateEdit ("", 0,100,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$edit[1]=GUICtrlCreateEdit ("", 0,200,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$edit[2]=GUICtrlCreateEdit ("", 0,300,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$edit[3]=GUICtrlCreateEdit ("", 0,400,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$edit[4]=GUICtrlCreateEdit ("", 0,500,600,100,$ES_AUTOVSCROLL+$WS_VSCROLL)
$update_BTN=GUICtrlCreateButton ("UPDATE", 0,600, 50)
GUISetState ()
update()
; will be append dont' forget 3rd parameter
;GUICtrlSetData ($myedit, "Second line",1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    IF $msg = $update_BTN then update()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
$ObjIE.quit


func lines($_text,$_lines)
   return stringleft($_text,stringinstr($_text,@cr,0,$_lines))
EndFunc

func update()
   GUICtrlSetData ( $myedit, $ObjIE.document.documentelement.outerHTML)

   $frames=$ObjIE.document.parentwindow.document.frames.length
   for $i=0 to 4
      GUICtrlSetData ($edit[$i],""); clear out old data
   Next
if $frames>0 then
  for $i = 0 to ($ObjIE.document.parentwindow.document.frames.length)-1
  GUICtrlSetData ( $edit[$i],$ObjIE.document.frames($i).document.body.outerHTML)
  if StringInstr($ObjIE.document.documentelement.outerHTML,"iframe") then GUICtrlSetData ( $edit[$i],@crlf & "iframes can be a problem",1)
  next
EndIf

EndFunc

func MyErrFunc()
   tooltip($oMyError.windescription,0,0)
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites
scriptkitty

Ok, continuing my examples for the new OBJ and IE. Here is some UDF you might find handy.

If nothing else, you can use as references to make your own.

for simplicity and easy of use, I use a global IE object of $ObjIE

hope you find it helpful

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        scriptkitty
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
Opt ("TrayIconDebug", 1)        ;0=no info, 1=debug line info
$oMyError = ObjEvent ("AutoIt.Error", "MyErrFunc"); Install a custom error handler

_IE_connect()
_IEdone()

msgbox(1,"400chars of html of the page",StringLeft($ObjIE.document.documentelement.outerHTML,400),5)

msgbox(1,"info","now I will find and click the forum link")
_IEclicklink("forum</a>")


msgbox(1,"info","Now I will go to login page and fill in some fields")
_IEdone()
_IEclicklink(">Log In</a>")

msgbox(1,"Info","time to fill in some stuff")
_IEdone()
_IE_form("name=UserName", "myname"); form number optional
_IE_form("password", "mypassword", 0)
_IE_formcheckbox("Privacy")

msgbox(1,"info","next I will click the login button")
_IE_formclick("Log me in")







;===============================================================================
;
; Function Name:    _IE_formclick
; Description:    Clicks something on a form
; Parameter(s):  $_find   - text to find
;                  $_form     - Number of form element (optional)
; Requirement(s):   $ObjIE must be an IE object
; Return Value(s):  On Success - Clicks
;                  On Failure - no failure yet
; Author(s):        scriptkitty 
;
;===============================================================================
;

Func _IE_formclick($_find,$_form = 0)
   For $i = 1 To $ObjIE.document.forms ($_form) .elements () .length - 1
      If StringInStr($ObjIE.document.forms ($_form) .elements ($i) .outerHTML, $_find) > 0 Then
         $ObjIE.document.forms ($_form) .elements ($i) .click()
      EndIf
   Next
EndFunc  

;===============================================================================
;
; Function Name:    _IE_formcheckbox
; Description:    Marks element as checked on a form
; Parameter(s):  $_find   - text to find
;                  $_form     - Number of form element (optional)
; Requirement(s):   $ObjIE must be an IE object
; Return Value(s):  On Success - marks element as checked
;                  On Failure - no failure yet
; Author(s):        scriptkitty 
;
;===============================================================================
;

Func _IE_formcheckbox($_find,$_form = 0)
   For $i = 1 To $ObjIE.document.forms ($_form) .elements () .length - 1
      If StringInStr($ObjIE.document.forms ($_form) .elements ($i) .outerHTML, $_find) > 0 Then
         $ObjIE.document.forms ($_form) .elements ($i) .checked = true
      EndIf
   Next
EndFunc  ;==>_IE_formcheckbox

;===============================================================================
;
; Function Name:    _IE_form
; Description:    Finds and fills element on a form
; Parameter(s):  $_find   - text to find
;                  $_form     - Number of form element (optional)
;                  $_fill     - Text to fill into element
; Requirement(s):   $ObjIE must be an IE object
; Return Value(s):  On Success - fills element on form
;                  On Failure - no failure yet
; Author(s):        scriptkitty 
;
;===============================================================================
;

Func _IE_form($_find, $_fill, $_form = 0)
   For $i = 1 To $ObjIE.document.forms ($_form) .elements () .length - 1
      If StringInStr($ObjIE.document.forms ($_form) .elements ($i) .outerHTML, $_find) > 0 Then
         $ObjIE.document.forms ($_form) .elements ($i) .value = $_fill
      EndIf
   Next
EndFunc  ;==>_IE_form

;===============================================================================
;
; Function Name:    _IEclicklink
; Description:    Clicks a link on page
; Parameter(s):  $_linktext   - text to find
;
; Requirement(s):   $ObjIE must be an IE object
; Return Value(s):  On Success - clicks link
;                  On Failure - no failure yet
; Author(s):        scriptkitty 
;
;===============================================================================
;
Func _IEclicklink($_linktext)
   While $ObjIE.busy
      Sleep(10)
   Wend
   For $_i = 0 to ($ObjIE.document.links () .length) - 1; count of links
      If StringInStr($ObjIE.document.links ($_i) .OuterHTML, $_linktext) > 0 Then
         $ObjIE.document.links ($_i) .click
         ExitLoop
      EndIf
   Next
EndFunc  ;==>_IEclicklink

;===============================================================================
;
; Function Name:    _IEdone()
; Description:    Checks to see if page is loaded
; Parameter(s):  none
;
; Requirement(s):   $ObjIE must be an IE object
; Return Value(s):  On Success - sleeps until loaded
;                  On Failure - no failure yet
; Author(s):        scriptkitty 
;
;===============================================================================
;
Func _IEdone()
   While $ObjIE.busy
      Sleep(10)
   Wend
EndFunc  ;==>_IEdone

Func _MyErrFunc()
   $HexNumber = Hex($oMyError.number, 8)
   Global $_IEError= ("We intercepted a COM Error !" & @CRLF & _
         "Number is: " & $HexNumber & @CRLF & _
         "Windescription is: " & $oMyError.windescription, 0, 0) 
   
   SetError(1); something to check for when this function returns
   Sleep(100); slight pause
EndFunc  ;==>_MyErrFunc

;===============================================================================
;
; Function Name:    _IE_connect
; Description:    Connects to a page, if URL not called will start one
; Parameter(s):  $url    - text of substring of URL (optional)
;
; Requirement(s):   Internet explorer must be installed
; Return Value(s):  On Success - connects and returns IE object
;                  On Failure - makes new IE object and returns 
; Author(s):        scriptkitty 
;
;===============================================================================
;
Func _IE_connect($url = "www.autoitscript.com")
   Dim $ObjShell = ObjCreate ("Shell.Application")
   Dim $ObjShellWindows = $ObjShell.Windows (); collection of all ShellWindows (IE and File Explorer)
   Global $ObjIE
   
   For $Window in $ObjShellWindows
      If StringInStr($window.LocationURL, $url) > 0 Then
         $ObjIE = $Window
         ExitLoop; We found it...
      Else
         $ObjIE = 0
      EndIf
   Next
   
   If isObj ($ObjIE) Then
      ConsoleWrite("--> $ObjIE now points to an IE Instance connected" & @CR)
   Else
      $ObjIE = ObjCreate ("InternetExplorer.Application")
      
      With $ObjIE
      .Visible = True
      .Navigate ($url)
      Do
         Sleep(50)
      Until .ReadyState = 4
      EndWith
      ConsoleWrite("--> No IE instance was found connected so made one" & @CR)
   EndIf
   Return $ObjIE
EndFunc  ;==>_IE_connect

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites
scriptkitty

IE Fun Part 2 or

Stupid Internet Explorer tricks:

Here is one way to have an IE slideshow.

Obj/Com support only in beta atm.

Just put the script in a directory with a bunch of .jpg or .gif files and it goes to town.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        scriptkitty
;
; Script Function:
;   simple fun IE slideshow
;
; ----------------------------------------------------------------------------
; Script Start

$delay = 2000; 2 seconds
$start = '<center><img src="file://' & @ScriptDir & '/'
$start = StringReplace($start, "\", "/")
$ObjIE = ObjCreate ("InternetExplorer.Application")
With $ObjIE
   .left = 0
   .top = 0
   .height = @DesktopHeight - 100
   .width = @DesktopWidth - 100
   .menubar = 0
   .toolbar = 0
   .statusbar = 0
   .Navigate ("blank:"); it helps to have a working IE page when you start changing it.
   .document.body.innerhtml = ""
EndWith

$filelist = StringSplit(_filefinder("*.jpg") & "|" & _filefinder("*.gif") , "|")

While WinExists("Invalid")
   $ran = Random(1, $filelist[0])
   _picchange($filelist[$ran])
   Sleep($delay)
Wend

Func _picchange($_pic)
   If StringLen($_pic) > 1 Then
      $ObjIE.document.body.innerhtml = $start & $_pic & '"></center>'
      $ObjIE.Visible = 1
   EndIf
EndFunc;==>_picchange

Func _filefinder($_fileEXT)
   Dim $_ret
   $_search = FileFindFirstFile($_fileEXT)
   If $_search = -1 Then
      Return
   EndIf
   While 1
      $_ret = $_ret & FileFindNextFile($_search) & "|"
      If @error Then ExitLoop
   Wend
   FileClose($_search)
   Return StringTrimRight($_ret, 1)
EndFunc;==>_filefinder

sidenote: Was just fooling around to make an old laptop into a walltop

http://www.grynx.com/index.php/projects/la...e-wall-walltop/

and thought, why not IE?.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites
scriptkitty

ScreenSaver version. Kiosk style, with speed up and slow down buttons.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        scriptkitty
;
; Script Function:
;   simple fun IE slideshow
;
; ----------------------------------------------------------------------------
; Script Start
HotKeySet("{F6}","_slower")
HotKeySet("{F7}","_speedup")


$delay = 2000; 2 seconds
$start = '<center><img src="file://' & @ScriptDir & '/'
$start = StringReplace($start, "\", "/")

$objIE = ObjCreate("InternetExplorer.Application")
    $objIE.Navigate("about:blank")
    $objIE.StatusBar= 0
    $objIE.MenuBar= 0
    $objIE.FullScreen="True"
    $objIE.toolbar = 0
    $objIE.document.body.bgcolor="#000000"
    $objIE.document.body.scroll="no"
    $objIE.Visible="True"

$filelist = StringSplit(_filefinder("*.jpg") & "|" & _filefinder("*.gif") , "|")

While ProcessExists("Iexplore.exe")
   $ran = Random(1, $filelist[0])
   _picchange($filelist[$ran])
   Sleep($delay)
Wend

Func _picchange($_pic)
   If StringLen($_pic) > 1 Then
      $ObjIE.document.body.innerhtml = $start & $_pic & '"></center>'
      $ObjIE.Visible = 1
   EndIf
EndFunc;==>_picchange

Func _filefinder($_fileEXT)
   Dim $_ret
   $_search = FileFindFirstFile($_fileEXT)
   If $_search = -1 Then
      Return
   EndIf
   While 1
      $_ret = $_ret & FileFindNextFile($_search) & "|"
      If @error Then ExitLoop
   Wend
   FileClose($_search)
   Return StringTrimRight($_ret, 1)
EndFunc;==>_filefinder

func _speedup()
   if $delay > 1000 then $delay=$delay-1000
   if $delay <= 1000 and $delay >100 then $delay=$delay/2
   tooltip($delay/1000 & " sec delay",0,0)
EndFunc

func _slower()
   if $delay <= 1000 then $delay=$delay*2
   if $delay > 1000 then $delay=$delay+1000
   tooltip($delay/1000 & " sec delay",0,0)
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

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  

×