How do I Submit/Click Button on IE using automation, if no id present, and all submitforms have the same name?

antlz

New Member
Joined
Oct 28, 2013
Messages
16
Hello again forum.

Yesterday I've managed to navigate through a webpage via vba, but I can't figure out the last step, or the one before it.

I need to click on a submit type button, but I can't figure out how to do it.

The problem is, I can't get the element by name, because all 3 share the same name.

This is the HTML part:
HTML:
 <!-- saved from url=****.do -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><TITLE>SYSTEM</TITLE><LINK rel=stylesheet type=text/css href=".***ro.css"><LINK rel=stylesheet type=text/css href="****o.css">
******** ********************1.2 type=text/javascript charset=utf-8 src="***4.js">
*********>
<LINK rel="shortcut icon" type=image/x-icon href="***icon.ico"><!-- PNG support script --><!-- width and heights of boxes w. Box-Model Problem  --></HEAD>
<BODY>
<DIV id=headband>
<DIV id=sysname><STRONG>SYSTEMSYSTEM</STRONG></DIV>
<DIV><SPAN id=logo></SPAN></DIV>
<DIV id=user>USER: <STRONG>USER</STRONG></DIV>
<DIV id=logout><A href="logout.do"><IMG title=Exit border=0 alt=Exit src="http://www.mrexcel.com/forum/images/exit16.png"></IMG></A></DIV>
<DIV id=toMenu><A href="backtomenu.do"><IMG title="Back to the main menu" border=0 alt=Tomenu src="http://www.mrexcel.com/forum/images/tomenu.png"></IMG></A> </DIV></DIV>
<DIV id=container>
<DIV class=pagecontent>
<DIV class=caption>Stat</DIV>
<DIV class=errdiv></DIV>
<FORM id=form1 method=post name=statBean action=**/stat.do>
<DIV class=buttonrow>
<TABLE>
<TBODY>
<TR>
<TD><A href="***init4.do"><IMG title="Back to the menu" border=0 src="http://www.mrexcel.com/forum/images/back16.png"></A></TD>
<TD><INPUT title="STAT1" *******=clearErrs() value="STAT111" type=submit name=act></TD>
<TD><INPUT title="STAT2" *******=clearErrs() value="STAT222" type=submit name=act></TD>
<TD><INPUT title="STAT3" *******=clearErrs() value=STAT333 type=submit name=act></TD></TR></TBODY></TABLE></DIV>
<TABLE>
<TBODY>
<TR>
<TD align=right>PERIOD</TD>
<TD class=star>*</TD>
<TD><INPUT maxLength=10 size=10 name=fromJsp__>-tól</TD>
<TD id=err1></TD></TR>
<TR>
<TD align=right></TD>
<TD class=star> </TD>
<TD><INPUT maxLength=10 size=10 name=tillJsp__>-ig</TD>
<TD id=err2></TD></TR></TBODY></TABLE></FORM></DIV></DIV></BODY></HTML>

This is my code:
Code:
Sub LogIn()
Dim IE As Object
Dim doc As Object
Dim username As Object
Dim pwd As Object
Dim strURL As String
Dim strUserName As String
Dim strPwd As String
Dim LoginForm As HTMLFormElement
Dim ReportForm As HTMLFormElement
Dim SendForm As HTMLFormElement
' Dim ieLinks As Object
' Dim Links As Object
Dim obj As Object
Dim idoszak1string As String
Dim idoszak2string As String
Dim reportdate1 As Object
Dim reportdate2 As Object
Dim sendbutton As Object

    idoszak1string = "..."
    idoszak2string = "..."

    strUserName = Application.InputBox(...)
    strPwd = Application.InputBox(...)

    strURL = "***login.jsp"
    
    
    
    Set IE = New InternetExplorerMedium
    IE.Visible = True
    
    IE.navigate strURL
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    Set doc = IE.document
    Set LoginForm = doc.forms(0)
    
    
    Set username = doc.getElementById("j_username")
    
    Set pwd = doc.getElementById("j_password")
    
    username.Value = strUserName
    
    pwd.Value = strPwd
 

    LoginForm.submit
    
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    
    IE.navigate "***it4.do"
        
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    
    IE.navigate "***stat.do?act=startStat"
    
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    
    Set doc = IE.document
    Set ReportForm = doc.forms(0)
    
    Set reportdate1 = doc.getElementById("fromJsp__")
    
    Set reportdate2 = doc.getElementById("tillJsp__")
    
    
    Set SendForm = document.forms
    
    
    reportdate1.Value = idoszak1string
    
    reportdate2.Value = idoszak2string
 
   
    Set sendbutton = document.querySelectorAll("[STAT3]")
    
    sendbutton.submit   
    
   
    
    Set IE = Nothing
    
    
    
End Sub

As you can see, i want to click STAT3, but it's value is not in " ".
How can I submit STAT3?

Thanks in advance,
Z
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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