PDA

View Full Version : Button Click in Internet - Button without 'Name'!!



23izkool
07-16-2011, 07:11 PM
Hi all,

I am having problem clicking a button in an Internet Browser where the source code for the button only gives the (1) input type & (2) id BUT not the (3) name!

SOURCE CODE FOR BUTTON WITHOUT NAME

<input type="button" id="ImportingButton" class="C00_Button1" value="Importingvalue" onclick="performUpload();"/>


I have already successfully written a code to click internet buttons WITH names:

SOURCE CODE FOR BUTTON WITH NAME

<input type="button" name="ImportingButton" id="ImportingButton" class="C00_Button1" value="Importingvalue" onclick="performUpload();"/>

VBA CODE TO CLICK BUTTON

Sub ClickButton()
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
Application.ScreenUpdating = False
Nm = 1234
Set appIE = New InternetExplorer
url = (the website link I'm trying to access)
' ---- click the editbutton (start) ----
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.name = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
' --- click the editbutton (end) ---
End Sub

** MODIFIED VBA CODE TO CLICK BUTTON **

Sub ClickButton()
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
Application.ScreenUpdating = False
Nm = 1234
Set appIE = New InternetExplorer
url = (the website link I'm trying to access)
' ---- click the editbutton (start) ----
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.ID = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
' --- click the editbutton (end) ---
End Sub

When I ran the above macro, the program hung & I had to force-stop the macro by pressing 'Ctrl-Break'
When I investigated the debugging portion --> it highlighted the code 'btnInput.ID...'

Believe this can be solved BUT no clue now..Hope someone can advise!!
Thanks everyone!!!

Crocus Crow
07-18-2011, 02:06 AM
"button only gives the (1) input type & (2) id".

Use getElementById then.