Solved

Internet Explorer Object and Automation and Access the DOM structure

Posted on 2003-10-29
32
12,291 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
ID: 9643688
There is a Frames property of Document object.
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 50 total points
ID: 9643824
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
ID: 9644144
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9644203
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
ID: 9644691
Good place to start is under "document" (Internet Explorer SDK option) in your MSDN Library
0
 

Author Comment

by:mikekwok
ID: 9647035
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
ID: 9647079
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
ID: 9647097
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
ID: 9647498
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
ID: 9647533
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
ID: 9684120
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
ID: 9686192
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
ID: 9691723
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
ID: 9691812
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
ID: 9693748
Hi, did you received my mail with your request?
0
 

Author Comment

by:mikekwok
ID: 9698608
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
 

Author Comment

by:mikekwok
ID: 9737418
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
ID: 9738875
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
ID: 9744380
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
ID: 9745689
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
ID: 9746606
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
ID: 9747208
"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
ID: 9748178
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
ID: 9794471
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
ID: 9796453
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
ID: 9926505
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
ID: 10647143
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
ID: 10649361
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
ID: 10649386
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
ID: 10974414
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
ID: 10997561
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
ID: 11001380
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form submit issue 11 89
Hide vba in gp 7 113
Copy a range from 1..n excel sheets to one destination sheet 2 66
Grunt script for Build Process 1 60
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

685 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