PDA

View Full Version : Hitting Submit using VBA in IE



ypatel1990
11-13-2014, 11:20 AM
Hello all,

I am having trouble with getting a javascript function to execute in vba. My script so far takes me to the website, logs in, goes to the correct page, and changes the drop down menu to the correct option. On this dropdown menu page there is no submit button until the drop down changes and I use .FireEvent (onchange) to make the submit button appear. The trouble I am having is with pressing the submit button which will open the new window. It seems that the submit is in a Function which I do not know how to manipulate in vba.

The script that shows where I run the javascript to get the submit button to appear is shown below.


With .document
' select shareholding
Set SecName = .getElementsByName("ctl00$ContentPlaceHolder1$RptSel$ddlReport")
SecName(0).Value = "279"
Set objURLpage = ie.document
Set objSELECTelement = objURLpage.getElementById("ctl00$ContentPlaceHolder1$RptSel$ddlReport")
objSELECTelement.selectedIndex = 2
objSELECTelement.FireEvent ("onchange")
With appIE
End With

This is the source code showing the javascript which references a doPostBack


onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$RptSel$ddlR eport\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_RptSel_ddlReport">


This is the source code for the post back function which I assume is what I need to hit submit.


<

scripttype="text/javascript">

//<![CDATA[

var
theForm = document.forms['aspnetForm'];

if
(!theForm) {

theForm = document.aspnetForm;

}

function
__doPostBack(eventTarget, eventArgument) {


if (!theForm.onsubmit || (theForm.onsubmit() != false)) {

theForm.__EVENTTARGET.value = eventTarget;

theForm.__EVENTARGUMENT.value = eventArgument;

theForm.submit();

}

}


Any help with this would be greatly appreciated. If any more information is needed please do let me know and I will provide what I can.

Thanks!

westconn1
11-13-2014, 01:20 PM
if you can access the form element, you could try to submit the form, or you could try posting the forms action if it is javascript

ypatel1990
11-13-2014, 02:03 PM
if you can access the form element, you could try to submit the form, or you could try posting the forms action if it is javascript

I tried multiple ways to submit the form but have been unsuccessful so far. Not exactly sure what you mean by posting the forms action however this was also a part of the source code it it helps any:


<

form name="aspnetForm" method="post" action="reportselection.aspx?ProgramID=230" id="aspnetForm">

<
div>

<
input type="hidden" name="ctl00_RadScriptManager1_TSM" id="ctl00_RadScriptManager1_TSM" value="" />

<
input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />

<
input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

<
input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />

<
input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"

westconn1
11-14-2014, 03:05 AM
formname="aspnetForm"method="post"action="reportselection.aspx?ProgramID=230"id="aspnetForm">the forms action is described