Controlling Internet Explorer

Ethan

New member
Joined
Aug 11, 2009
Messages
4
Location
Charlotte, NC
Programming Experience
10+
Hello,

This is my first post. I am just learning VB.NET. Glad to be here.

I am having a problem similar to the above.

I am trying to cycle through all the elements of a frame, find the right html link, and click it. I am using
Dim Coll As IHTMLElementCollection
Dim Ele As IHTMLElement

Coll = HTMLDoc.getElementsByTagName("input")
For Each Ele In Coll
etc....

In the for loop (For Each Ele In Coll), I dont think there are any values in the Collection. I only get one pass through the loop. Can someone help me with an example of finding a link on a website and clicking it?
 
Just to expound on my question a little..

I am writing a program that will:

1. log into a website
2. look up a customer file on the website
3. open each html page in the file
4. compile each page into one large html file
5. Convert the file to PDF format

I have the code that does steps 1 through 3 written in VBA and it works. I have the code for steps 4 and 5 in VB.NET and it works. What I can't get working is step 3 in VB.NET.

The hyperlinks to each page in the customer file are contained in a frame. The source code for the frame looks like this:

<HTML>
<HEAD>
<TITLE>WPII</TITLE>
<SCRIPT LANGUAGE='JavaScript' SRC='../js/wp2common.js'>
</SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>
<!--
function GoTo(destination) {
if (parent.DataFrame.document.mainForm.WP_FORM_SUBMITTED.value!='TRUE') {
parent.DataFrame.document.mainForm.SCREEN.value=destination
parent.DataFrame.document.mainForm.FRAME.value='PARENT'
parent.DataFrame.document.mainForm.target='_top'
parent.NavFrame.submitForm()
}
}
function Needed(screen) {
w=window.open('', '', 'width=500,height=250,resizeable=yes');
w.document.write ('<html><head></head><body><center><b>REQUIRED TO COMPLETE</b><br><br>');
if (screen == 'Arrears')
{
w.document.write('Screen Completed.');
}
else if (screen == 'BorrIncome')
{
w.document.write('Available Income<br>');
}
else if (screen == 'NewBorrIncome')
{
w.document.write('Screen Completed.');
}
else if (screen == 'BorrInfo')
{
if (isNull(parent.DataFrame.document.mainForm.BORR_name_borr_first.value))
w.document.write('Borrower\'s First Name<br>');
if (isNull(parent.DataFrame.document.mainForm.BORR_name_borr_lst.value))
w.document.write('Borrower\'s Last Name<br>');
if (isNull(parent.DataFrame.document.mainForm.BORR_addr_strt.value))
w.document.write('Borrower\'s Street Address<br>');
if (isNull(parent.DataFrame.document.mainForm.BORR_addr_city.value))
w.document.write('Borrower\'s City<br>');
if (isNull(parent.DataFrame.document.mainForm.BORR_addr_st.options[parent.DataFrame.document.mainForm.BORR_addr_st.selectedIndex].text))
w.document.write('Borrower\'s State<br>');
if (isNull(parent.DataFrame.document.mainForm.BORR_addr_zip.value))
w.document.write('Borrower\'s Zip<br>');
if ( !(isNull(parent.DataFrame.document.mainForm.BORR_name_borr_first.value)) && !(isNull(parent.DataFrame.document.mainForm.BORR_name_borr_lst.value)) && !(isNull(parent.DataFrame.document.mainForm.BORR_addr_strt.value)) && !(isNull(parent.DataFrame.document.mainForm.BORR_addr_city.value)) && !(isNull(parent.DataFrame.document.mainForm.BORR_addr_st.options[parent.DataFrame.document.mainForm.BORR_addr_st.selectedIndex].text)) && !(isNull(parent.DataFrame.document.mainForm.BORR_addr_zip.value)) )
w.document.write('Screen Completed.');
}
else if (screen == 'NewBorrInfo')
{
w.document.write('Screen Completed.');
}
else if (screen == 'BusPlan')
{
w.document.write('Screen Completed.');
}
else if (screen == 'CE')
{
w.document.write('Screen Completed.');
}
else if (screen == 'Warnings')
{
w.document.write('Must view Comments Screen<br>');
}
else if (screen == 'Contribtn')
{
w.document.write('Screen Completed.');
}
else if (screen == 'Cntct')
{
w.document.write('Screen Completed.');
}
else if (screen == 'Hud')
{
w.document.write('Gross Amount Due Seller<br>');
w.document.write('Reduction in Amount Due Seller<br>');
}
else if (screen == 'Letters')
{
w.document.write('Screen Completed.');
}
else if (screen == 'Loan')
{
w.document.write('Current PITI<br>');
w.document.write('Primary Default Reason<br>');
}
else if (screen == 'Property')
{
w.document.write('Screen Completed.');
}
else
{
w.document.write('Not Applicable');
}
w.document.write('</center></body></html>');
w.document.close();
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR='WHITE'>
<FORM NAME='ToDo'>
<IMG SRC='../images/WpII.gif'>
<H3><CENTER>To Do</CENTER></H3>
<CENTER>
<TABLE BORDER='1'>
<TR><TD><A HREF="javascript:Needed('BorrInfo')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('BorrInfo')"><font color=BLACK>Borrower Information</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('BorrIncome')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('BorrIncome')"><font color=BLUE>Borrower Financials</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Property')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Property')"><font color=BLACK>Property</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Loan')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Loan')"><font color=RED>Loan</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Analyze')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Analyze')"><font color=BLACK>Analyze</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Warnings')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Warnings')"><font color=RED>Warnings and Comments</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Letters')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Letters')"><font color=BLACK>Letters</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('Cntct')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('Cntct')"><font color=BLACK>Contact</FONT></A></TD></TR>
<TR><TD><A HREF="javascript:Needed('WOSummary')"><IMG SRC="../images/ToDoNeeded.gif" WIDTH="10" HEIGHT="10" ALIGN="BOTTOM" border=0></A> <A HREF="javascript:GoTo('WOSummary')"><font color=BLACK>Workout Summary</FONT></A></TD></TR>
</TABLE>
</CENTER>
<INPUT TYPE='HIDDEN' NAME='CURRENT_DATE' VALUE='08/12/2009'>
<INPUT TYPE='HIDDEN' NAME='WP_QName' VALUE='SERV.WORKOUT.NONPERFP3'>
</FORM>
</BODY>
</HTML>

My VB.NET code looks like this (repeated several times for each link listed above):

'****************Navigate to Loan Screen**********************
Do While .Busy : Application.DoEvents() : Loop
Do While .ReadyState <> 4 : Application.DoEvents() : Loop

htmlDoc = .Document.frames("ToDoFrame").Document
htmlColl = htmlDoc.getElementsByTagName("A")
For Each htmlInput In htmlColl
If htmlInput.innerText = "Loan" Then
htmlInput.focus()
htmlInput.click()
Exit For
End If
Next htmlInput
Do While .Busy : Application.DoEvents() : Loop
Do While .ReadyState <> 4 : Application.DoEvents() : Loop

'**************Set focus before printing***********************

Do While .Busy : Application.DoEvents() : Loop
Do While .ReadyState <> 4 : Application.DoEvents() : Loop
Do Until .Busy = False
Loop
While objIE.ReadyState <> 4
Application.DoEvents()
End While
While objHTML.readyState <> "complete"
Application.DoEvents()
End While

htmlDoc = .Document.frames("DataFrame").Document
htmlColl = htmlDoc.getElementsByTagName("INPUT")
For Each htmlInput In htmlColl
If htmlInput.name = "WKMDL_dt_ddlpi" Then
htmlInput.focus()
htmlInput.click()
.ExecWB(6, 2) 'print and don't prompt user
Exit For
End If
Next htmlInput

It's only passing once through each loop, as if it's not finding the elements at all. I'm really stuck. Can someone help me figure this out?
 
Okay I figured it out

All that trouble and the solution was a single missing character.

I had been using:
VB.NET:
Dim htmlInput As mshtml.HTMLElement

When I changed it to:
VB.NET:
Dim htmlInput As mshtml.IHTMLElement

The code I posted above worked.
 
Back
Top