Solved

Internet Explorer Object and Automation and Access the DOM structure

Posted on 2003-10-29
32
12,216 Views
Last Modified: 2013-11-19
I would like to ask where I can get the full documentation of the Internet Explorer Object with Automation and accessing the Dom structure of the homepage in Internet Explorer(Q1).

My situation is that I want to login to a homepage and do some process automatically ( for example hotmail  and login and then compose a email. )
I know how to create an Internet Exploerer Object in Visual Basic. I know how to type the username and the password and then click the submit button and login. However, (Q2)if there are 2 frames in the homepage, in one of the frames there are some hyperlinks there , would you tell me how can I simulate clicking the hyperlinks and load it in that frame ? (Q3) How can i load the hyperlinks that should load when i click on some images on that frame ? I know how to use the keyboard_event , but I don't want to use this approach since if the internet explorer lost focus then it will cause error.


Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "http://www.google.com"
    IE.Visible = True
    Do While IE.Busy
       DoEvents
    Loop

I use these code to create Internet Explorer Object


IE.Document.All("username").Value = "mikekwok"
IE.Document.All("password").Value = "12345"
Ie.DOcument.All("submit").Click

These code are for typing the login username and password and click the button.

If there are more than 1 frames after login ,how can I locate the frames and the elements inside for programming in Visual Basic ?
Thanks.
0
Comment
Question by:mikekwok
  • 18
  • 10
  • 3
  • +1
32 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
There is a Frames property of Document object.
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 50 total points
Comment Utility
There were a several Mind's issues from Microsoft regarding what you need but that people chnage the site so often that i can't found them any more. If you want, i could send those articles by mail.
Cheers
PS: In the meantime, take a look at www.angelfire.com/realm/vb-shared/index.html under "IE" topic.
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 50 total points
Comment Utility
Private Sub Form_Load()
    Dim IE As Object, Temp1 As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.pageresource.com/html/frameex5.htm"
    Do Until IE.readyState = 4
        DoEvents
    Loop
    IE.document.frames(0).document.All.tags("a")(0).Click
End Sub

The above will click the first (0) link ("a") in the first (0) frame.


It'd be alot easier using the Microsoft HTML Object Library (References) as the methods/properties are exposed to you.
0
 
LVL 17

Expert Comment

by:zzzzzooc
Comment Utility
Here's an example of enumerating through the frames and links (i didn't bother to try using objects/variants for the element collections):

Private Sub Form_Load()
    Dim IE As Object, iLoop1 As Variant, iLoop2 As Variant
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.pageresource.com/html/frameex5.htm"
    Do Until IE.readyState = 4
        DoEvents
    Loop
    For iLoop1 = 0 To IE.document.frames.length - 1
        If IE.document.frames(iLoop1).Name = "left_frame" Then
            For iLoop2 = 0 To IE.document.frames(iLoop1).document.All.tags("a").length - 1
                If IE.document.frames(iLoop1).document.All.tags("a")(iLoop2).outerText = "Back to the HTML frames tutorial. " Then
                    'This is our link! Click it.
                    IE.document.frames(iLoop1).document.All.tags("a")(iLoop2).Click
                    Exit Sub
                End If
            Next iLoop2
        End If
    Next iLoop1
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
Good place to start is under "document" (Internet Explorer SDK option) in your MSDN Library
0
 

Author Comment

by:mikekwok
Comment Utility
Richie_Simonetti, I want the articles you mentioned, would you send to my email address, please ? michael.kwok@alumni.ust.hk
Thanks.
0
 

Author Comment

by:mikekwok
Comment Utility
zzzzzooc, you have said "
It'd be alot easier using the Microsoft HTML Object Library (References) as the methods/properties are exposed to you."

In Visual Basic, I click Project -> References and select Microsoft HTML Object Library.  However, I cannot find a list showing the method/properties when i type IE.Document. .
I cannot see a list after clicking the . after I typed " IE.Document" . Would you please tell me how ?

I also want to know where can I get all of the properties and the methods when i type IE.Document ? any website providing these information ? Thanks.

I also want to know if there is any method to show the whole DOM structure of the homepage . for example , http://www.pageresource.com/html/frameex5.htm ?
0
 

Author Comment

by:mikekwok
Comment Utility
zzzzzooc, this link : "IE.document.frames(0).document.All.tags("a")(0).Click" , where is the "a" ? I cannot find any link that has "a" as name. Would you show me where is the "a" ? Thanks


<HTML>

<HEAD>
<TITLE>FRAME 10</TITLE>

<SCRIPT language="JavaScript">
<!----hide
function change2()
{
parent.left_frame.location="12frame.htm";
parent.right_frame.location="13frame.htm";
}
//------>
</SCRIPT>

</HEAD>

<BODY bgcolor="#FFFFFF" text="#000000">

<CENTER>
This is page1.htm from the example.
<BR>
<BR>
Click the link below to change both frames.
<BR>
<A HREF="javascript:change2()">Change 2 Frames</A>
<P>
<HR>
<P>
<A HREF="frame4.htm" target="_top">Back to the <B>HTML</B> frames tutorial.
<P>
<A HREF="/jscript/jframe2.htm" target="_top">Back to the <B>JavaScript</B> frames tutorial.
<BR>
<BR>

</CENTER>

</BODY>
</HTML>
0
 

Author Comment

by:mikekwok
Comment Utility
If there is Javascript in the html :
      document.write('<A HREF="JavaScript: SubmitForm()">\n');
      document.write('<IMG SRC="images/ic_send.gif" BORDER=0></A>\n');

how can I click this URL in the IE in VB ?
Thanks.
0
 

Author Comment

by:mikekwok
Comment Utility
I know how to solve clicking the Image !

If IE.Document.frames(iLoop1).Document.All.tags("IMG")(iLoop2).href = "/images/ic_send.gif" Then
    IE.Document.frames(iLoop1).Document.All.tags("IMG")(iLoop2).Click
EndIf


However, if there is a dialog box pop up and you need to press "okay" or "cancel" how can I press the button ?

Thanks.
0
 

Author Comment

by:mikekwok
Comment Utility
zzzzzooc, you have said "It'd be alot easier using the Microsoft HTML Object Library (References) as the methods/properties are exposed to you" ... How can all those methods/properties expose to me when i type  "IE." in Visual Basic ?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
To get the list do some like this:

dim iedoc as htmldocument


in documentcomplete event


set iedoc = ie.document



After that, every time you type dot after iedoc you will see methods and properties of document.
0
 

Author Comment

by:mikekwok
Comment Utility
I would like to ask if a browser open a new browser , how can i set the Ie object to that new broswer in VB so that I can access the browsers' DOM ?
0
 

Author Comment

by:mikekwok
Comment Utility
I have solved the problem :

Dim shWin       As New ShellWindows
    Dim IE_loop          As InternetExplorer
   
    For Each IE_loop In shWin
        If IE_loop.LocationURL = "http://www.google.com.hk/" Then
            'navigate in same window
            IE_loop.Navigate "http://www.ust.hk"
            Exit For
        End If
    Next
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Hi, did you received my mail with your request?
0
 

Author Comment

by:mikekwok
Comment Utility
Yes, I have received ur mail . Very thx !!!

by the way, I would like to ask if there is any method to see the whole DOM structure of the hompage .
U can take a look on my question :

http://www.experts-exchange.com/Web/Web_Languages/Q_20790515.html
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:mikekwok
Comment Utility
After I login to a homepage, it pop up a dialog : "Secure Information. This Page contains both secure and non-secure items. Do you want to display the non-secure items ?"
my current approach to solve this problem is to use AppActivate "Security Information" and then press enter using the keysboard event.

Would somebody tell me how can i know when the secure information dialog s pop up and then i do something after pop u p?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
That depends upon security settings on your Internet Explorer regarding activex/java stuff that was not signed as secure for scripting/web usage. If you don't mind that, you could change security settings at IE configuration (i DONT'T LIKE that approach)
0
 

Author Comment

by:mikekwok
Comment Utility
i also don't want to disable the security settings at IE configuration. Do you know how to know when this popup dialog open in visual basic ?
i am using visual basic with IE object automation.
0
 

Author Comment

by:mikekwok
Comment Utility
would you tell me how to change security settings at IE configuration so that the security information dialog will not pop up ?
Also,If there are 2 frames in a homepage, how can it detect if the content of 1 of the frames finish loading in Visual Basic ?
0
 

Author Comment

by:mikekwok
Comment Utility
I know how to solve the problem .
Do until IE.busy = false
   doevents
loop


However, I don't know how can i set an IE object reference to the Internet Explorer which is opened by another Internet Explorer ?

My situation is that after clicking a button in Internet Explorer, it popup some IE . i need to locate all those IE and click something in the IE.
would somebody please help me ?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
"i also don't want to disable the security settings at IE configuration. Do you know how to know when this popup dialog open in visual basic ?"

As long as i know, there is no event to manage this kind of thing.


"Also,If there are 2 frames in a homepage, how can it detect if the content of 1 of the frames finish loading in Visual Basic ? "

see your other Q for a comment.
Cheers
0
 
LVL 17

Expert Comment

by:zzzzzooc
Comment Utility
Sorry for late replies.

>>zzzzzooc, you have said "It'd be alot easier using the Microsoft HTML Object Library (References) as the methods/properties are exposed to you" ... How can all those methods/properties expose to me when i type  "IE." in Visual Basic ?

Go to View -> Object Browser -> MSHTML.Ctl. All the methods/properties/classes should be listed there for HTMLDocuments. You can just use that as a resource for using it through the CreateObject().

>>zzzzzooc, this link : "IE.document.frames(0).document.All.tags("a")(0).Click" , where is the "a" ? I cannot find any link that has "a" as name. Would you show me where is the "a" ? Thanks

The "a" refers to "A" elements such as: "<A HREF="javascript:change2()">Change 2 Frames</A>". You'll notice the "<A></A>".
 



Question seems to be mostly resolved so I won't  bother.
0
 

Author Comment

by:mikekwok
Comment Utility
Would somebody please tell me how to check Internet Explorer Language Version ( English, Traditional Chinese, etc)  using Visual Basic 6 ? I know how to detect Internet EXplorer Version ... http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11203796.html
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
First of all, it is NOT a good idea to have an OS in one language and IE in other.
0
 

Author Comment

by:mikekwok
Comment Utility
Public Sub click_Security_dialog(Language As String)
    On Error GoTo ErrorHandler
    If Language = "e" Then
        AppActivate "Security Information"
    ElseIf Language = "tc" Then
        AppActivate "&#23433;&#20840;&#24615;&#36039;&#35338;"
    End If
    Dim clskey As New clsKeyboard
    Call clskey.PressKeyVK(keyReturn)
    Exit Sub
ErrorHandler:
Wait 1
Resume
End Sub

This code is for pressing dialog when internet explorer open. But it doesn't work when i try to open more than 1 internet explorer using visual basic and in these internet explorers pop up dialogs.

would some body tell me how to solve my problem ?  my program open 2 browsers and 2 pop up dialog and i need to press enter on that. it sometimes work but it sometimes doesn't work using the code above.
0
 

Author Comment

by:mikekwok
Comment Utility
If the homepage loads a java applet ? How can I access the textfield in the java applet using Visual Basic 6 and Internet Explorer Object ?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
it is a little tricky since everytime you load the same page in the same instance of webbrowser/internet explorer, the name of the controls embedded inside applet change.
Let me see if i can find the code in my HD.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
There is an Applets property collection of the HTMLDocument object (MSHTL library), maybe you could start from there. I still search for the example code.
0
 

Author Comment

by:mikekwok
Comment Utility
Richie Simonetti , would u please tell me more information on how to access the Applets using Visual Basic ?

After I login to a homepage, it pop up a dialog : "Secure Information. This Page contains both secure and non-secure items. Do you want to display the non-secure items ?"
Would you please tell me how to click the "yes" button through the DOM structure? THanks.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
As long as i know, i think yoy can't access that window from DOM.
The only waqy that comes to me in this moment is using an "external" app that search for every window opened in the system and when locate that window, send a [ENTER] key stroke.
0
 

Author Comment

by:mikekwok
Comment Utility
Would you please tell me more detail on using an "external" app that search for every window opened in the system and sedn [ENTER] key stroke.?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now