Jump to content
Sign in to follow this  
LOULOU

Automating Internet Explorer

Recommended Posts

If someone is working on automating internet explorer with multi frameset and com object , we can talk about because it's very diificult

Thanks in advance

Share this post


Link to post
Share on other sites

Sure, I work with it a lot. Afraid I can only help you with the new beta, and using IE.

Here is part of my script. Hope this helps point out how to do frames:

$ObjIE=IE_connect(); see my connect function or make your own. 
if stringinstr($ObjIE.document.body.innerhtml,'FRAME name=lpctop')>0 Then; this was just a check I had to make sure I was on the right frame.
      if StringInStr($ObjIE.document.frames(2).document.body.innerHTML,'<FORM name=posForm')>0 then
      With $ObjIE.document.frames(2).document.forms("Formname")

 .password.value = "your password"
 .ponumber.value = "NA"
 .submitbt.click(); if non standard submit button, use a click like this.

    EndWith
EndIf

I didn't make the connect function from scratch, I liked someone elses code and customised it.

left most of the old code in this example. Mine is about 5 lines. I also added part so that it makes an object if it can't find one exhisting.

Frames are a bit tricky, I sugest making sure you have frames exhisting, and fully loaded, which is a bit tough since every frame has its own ready state, but anyway it isn't too hard once you get the basics down.

func IE_connect()
Dim $ObjShell = ObjCreate("Shell.Application")
Dim $ObjShellWindows = $ObjShell.Windows(); collection of all ShellWindows (IE and File Explorer)
Dim $ObjIE

For $Window in $ObjShellWindows
    If StringInStr($window.LocationURL,"http:")>0  or StringInStr($window.LocationURL,"https:")>0 or StringInStr($window.LocationURL,"ftp:")>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("http://www.autoitscript.com")
  Do
    Sleep(50)
  Until .ReadyState = 4
EndWith
    ConsoleWrite("--> No IE instance was found connected so made one" & @CR)
EndIf
Return $ObjIE
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

anyway, start with getting $ObjIE.document.body.innerhtml

You will see a bunch of html, that includes frameset stuff.

next use $ObjIE.document.frames(1).document.body.innerHTML and take a look at that.

depending on how many frames you have, the # in frames(#) will change to reflect them.

when you find the right frame, you can start working with the information, I showed a form.

now to save a lot of typeing and easier to read you can see these two identical code examples:

With $ObjIE.document.frames(2).document.forms("Formname")
.password.value = "your password"
.ponumber.value = "NA"
.submitbt.click()
EndWith

$ObjIE.document.frames(2).document.forms("Formname").password.value = "your password"
$ObjIE.document.frames(2).document.forms("Formname").ponumber.value = "NA"
$ObjIE.document.frames(2).document.forms("Formname").submitbt.click()

I like the use of with personally, but here you can see it explained a bit.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

This code

$ObjIE.document.frames(2).document.forms("Formname").password.value = "your password"

Works only if there is one frameset but with two or three frameset we can't arrive accessing to the document.forms

Did you try with several frameset ?

Share this post


Link to post
Share on other sites

I am missing your wording.

There are multiple framesets? or multiple frames?

Are they Iframes, or standard frames.

Basically you need to understand the HTML of the page in order to get to the right spot.

If I hear you correctly, and you looked in the html of:

$ObjIE.document.frames(1).document.body.innerHTML you would see a frameset tag?

You are saying that you have a page with say 4 frames, Main, subframe1, subframe2,and subframe3. and one of those frames has a few more frames in it?

if you give me an example site, I might be able to help a bit more. Or faster..

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I can't give you the adress of the website because it is an Intranet.

The structure of the site is

<FRAMESET>

<FRAME1>

<FRAMESET>

<FRAME2>

<FRAME3>

</FRAMESET>

</FRAMESET>

I want ot access to a link which is on FRAME2 to simulate a click. This one walk when there is only one frame but with thazt's structure it doesn't walk

Here is a part of code in a real website with the following structure

<FRAMESET>

<FRAME>

</FRAMESET>

that you can test in real and works perfectly

Dim $ObjShell = ObjCreate("Shell.Application")
Dim $ObjShellWindows = $ObjShell.Windows(); collection of all ShellWindows (IE and File Explorer)
Dim $ObjIE

; URL of IE instance we want to find
Dim $URL = "http://www.powerboutique.com/"

$oShell = ObjCreate("shell.application"); Get the Windows Shell Object
$oShellWindows=$oShell.windows      ; Get the collection of open shell Windows

if not Isobj($oShellWindows) then
  Msgbox(0,"Error","Failed to obtain shell windows. Error: " & @error)
  exit
endif

; Now we search through all open Shell Windows and locate our internet page

$MyIExplorer=""

for $Window in $oShellWindows    ; Count all existing shell windows
; Note: Internet Explorer appends a slash to the URL in it's window name
  if $window.LocationURL = $URL  then 
      $MyIExplorer=$Window
      exitloop
  endif

next

if not IsObj($MyIExplorer) then
  MsgBox(0,"Error","Could not find a running instance of the internet explorer")
  exit
endif
;Cette fonction Marche dans une frame 


for $i = 0 to $MyIExplorer.parent.document.frames.index_front.document.all.tags("A").length
if StringStripWs($MyIExplorer.document.frames.index_front.document.links($i).InnerText,3) ="1" Then
$MyIExplorer.document.frames.index_front.document.links($i).click()
     exitLoop
     Endif 
 next

I hope it can give you an idea of what i want to do

Edited by LOULOU

Share this post


Link to post
Share on other sites

Maybe this will help:

DIM $MyIExplorer=ObjCreate("InternetExplorer.Application")

With $MyIExplorer
  .Visible = True
  .Navigate("http://www.powerboutique.com/")
  Do
    Sleep(50)
  Until NOT .busy
sleep(2000)
EndWith

msgbox(1,"how many frames?",$MyIExplorer.document.parentwindow.document.frames.length)
$frames=$MyIExplorer.document.parentwindow.document.frames.length
if $frames>0 then 
  for $i = 0 to ($MyIExplorer.document.parentwindow.document.frames.length)
  msgbox(1,"frameHTML"& $i,$MyIExplorer.document.frames($i).document.body.innerHTML)
     for $l= 1 to $MyIExplorer.document.frames($i).document.links.length
        MsgBox(1,"link "& $l & " frame"& $i,$MyIExplorer.document.frames($i).document.links($l).href)   
     Next
  next 
EndIf

edit, to see full HTML of parent, use:

MsgBox(1,"Full HTML of Parent", $MyIExplorer.document.documentElement.outerHTML)

When using stuff with frames it can get a bit wierd.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Maybe this will help:

DIM $MyIExplorer=ObjCreate("InternetExplorer.Application")

With $MyIExplorer
  .Visible = True
  .Navigate("http://www.powerboutique.com/")
  Do
    Sleep(50)
  Until NOT .busy
sleep(2000)
EndWith

msgbox(1,"how many frames?",$MyIExplorer.document.parentwindow.document.frames.length)
$frames=$MyIExplorer.document.parentwindow.document.frames.length
if $frames>0 then 
  for $i = 0 to ($MyIExplorer.document.parentwindow.document.frames.length)
  msgbox(1,"frameHTML"& $i,$MyIExplorer.document.frames($i).document.body.innerHTML)
     for $l= 1 to $MyIExplorer.document.frames($i).document.links.length
        MsgBox(1,"link "& $l & " frame"& $i,$MyIExplorer.document.frames($i).document.links($l).href)   
     Next
  next 
EndIf

edit, to see full HTML of parent, use:

MsgBox(1,"Full HTML of Parent", $MyIExplorer.document.documentElement.outerHTML)

When using stuff with frames it can get a bit wierd.

<{POST_SNAPBACK}>

In fact it appears , that's my first windows is not the parent windows but a child windows. whane i try your program with a parent windows all is good but with a child windows it isn't walk.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...