How to clear ComboBoxes and InputBoxes of a webpage with VBA

vba_newbie2013

New Member
Joined
Jun 18, 2013
Messages
29
Hey, i've got a tool that automates the process fo entering information into a webpage. Except if a user has already been there the webpage's cookies remember the data the user has already entered and automatically fills everything. But i want the tool to be able to run through multiple times which at the moment is not possible. All the fields values in the webpage are already set via the HTML so i've tried a simple

IE.Document.getElementById(insert the element here) = "" <-- nothing to clear the box.

Yet that throws a 'Object doesn't support this property or method' error. I was wondering if there was a way to maybe make it forget the prior information or the ability to clear the already entered information. Thanks for any help anyone can provide!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
A familiar question perhaps, but can we see the code?
 
Upvote 0
Yea sure. Getting the same error as mentioned above. I've tried to navigate to the URL that doesnt have all the information, but that doesnt seem to work. It would seem the website itself saves all this information.

Code:
Dim IE As InternetExplorer
Dim myZip As Long
Dim siteZip As Object
Dim URL As String
Dim gender As Object
Dim objInputs As Object
Dim countyOptions As Object
Dim countyChoice As String
Dim choCounty As Object
Dim tobaccoTrue As Object

Sub Macro_1()
myZip = "29020"

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "[URL="http://www.ehealthinsurance.com/individual-family-health-insurance"]Individual and Family Health Insurance[/URL]"
IE.navigate (URL)

Do
DoEvents
Loop Until IE.readyState = 4

Set siteZip = IE.document.getElementById("census_zipCode")
siteZip.Value = ""

Set gender = IE.document.getElementById("census_primary_gender")
gender.Value = "MALE"

Set objInputs = IE.document.getElementsByTagName("input")
For Each ele In objInputs
If ele.Title Like "Get Individual & Family Health Insurance Quotes" Then
ele.Click
End If
Next

'Wait till page has loaded
Application.Wait Now + TimeValue("00:00:02")

'County Selection
'Enter County
countySuc = True
countyChoice = "Kershaw"
Set countyOptions = IE.document.forms(1).all("census.county")
countyChoice = UCase(countyChoice)
For i = 0 To countyOptions.Length - 1
If countyChoice = countyOptions(i).innerText Then
countyOptions.Value = countyChoice
countySuc = True
Exit For
Else
countySuc = False
End If
Next i
If countySuc = False Then
MsgBox ("The county you entered is incorrect. Your options are: " & countyOptions(1).innerText & " and " & countyOptions(2).innerText)
Exit Sub

End If
'Tobacco Choice
Set tobaccoTrue = IE.document.getElementById("census_primary_tobaccotrue")
tobaccoTrue.Click

End Sub
 
Upvote 0
The first problem, and I kind of touched on this in the other thread, is that siteZip refers to a label element, not an input element.

I think what you really should do is access the controls via the form.

For example, to reset the zip.
Code:
    Set frm = IE.document.forms(1)
    
    Set siteZip = frm.all("census.zipCode")
    siteZip.Value = ""

Oh, and use the names instead of id as the ids don't seem to be unique.

For the input controls it seems to be census.<controlname>

For example, the county dropdown has the name 'census.county'.
 
Upvote 0
Once again Norie you cease to amaze. Quick question: I've used the ID's for all my userforms interaction with the page and it seems to work. Should i go back and change them to form references instead?
 
Upvote 0
I've not examined the whole page and it's innards but from what I've seen so far I would say yes.

I suppose you could compare using the form when referencing the controls to when you reference controls on a userform in a workbook.

If that makes any kind of sense.:)
 
Upvote 0
Hopefully you come back here again Norie. Got one last quick question. Is there a way to test what type a object is. For instance with this if you havent entered a zip code yet then the county selection is hidden. Is it possible to do something along the lines of:

If censusCounty.Type = "hidden" Then
do something

Once again thanks for all the help you have been providing me along the way.
 
Upvote 0
I'm not sure the county dropdown even exists when the page is first loaded.

I'll need to have another look.
 
Upvote 0
Hey again Norie! As i was working on this last night this 'quick question' turned into a multiple of smaller qestions so i apologize in advance. Instead of just testing whether the county comboBox is on the page i also need to test whether the user has entered valid zip and county. I've found that when the user does enter invalid information the webpage adds a 'Important Message: do this to fix the problem.' to the webpage that didnt exist before the error. So i was thinking on top of being able to test whether the comboBox for county is there is there a way to test if this 'Important Message' pops up so i can relay back to my user that they need to enter some valid info. Once again Norie thanks for all the help you have provided:)!

Edit: Hey! just realized i actually already have error catching for the county, but none for the zipcode. So i guess that means one less question.
 
Last edited:
Upvote 0
Actually have another question. How do i click on a a link that has no name or id. Here's the HTML that i think contains the link i'm trying to click:

Code:
[COLOR=#0000ff]<[/COLOR][COLOR=#800000]li[/COLOR][COLOR=#ff0000]class[/COLOR][COLOR=#0000ff]="bold">[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#ff0000]href[/COLOR][COLOR=#0000ff]="/ehi/ifp/all-plans?clearFilters=true" [/COLOR]
[COLOR=#ff0000]*******[/COLOR][COLOR=#0000ff]="s_objectID='ShowAllPlansTop';" >[/COLOR]Show All 81 Plans[COLOR=#0000ff]</< font>[COLOR=#800000]a[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]</< font>[COLOR=#800000]li[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]     <[/COLOR][COLOR=#800000]li[/COLOR][COLOR=#0000ff]>[/COLOR]Showing 10 of 81 Plans[COLOR=#0000ff]</< font>[COLOR=#800000]li[/COLOR][COLOR=#0000ff]>[/COLOR]
[/COLOR][/COLOR][/COLOR]
I'm trying to select the 'Show All Plans' hyperlink on the results page of the previously mentioned website, but am unsure as to how to follow through. Thanks Again!
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,139
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top