PDA

View Full Version : Solved: Automating Submission of Javascript Form



Treat
03-21-2013, 02:53 PM
I changed departments at work and discovered that they were doing several very repetitive tasks manually. I was able to write a script to extract customer data from our ticketing system but I've run into a snag interfacing with with a javascript applet. My data is a spreadsheet with a list of numbers when I try to submit the form with .submit, I don't get the same result as I do when clicking the continue button.

Here is my code so far (currently free of the loops and references to the spreadsheet until I get the javascript part figured out):



Private Sub ProcessDisconnects()
Dim i As Long
Dim IE As InternetExplorer
Dim URL As String
Dim Websource As String
Dim ieDoc As Object
Dim TNTest As String

URL = "Intranet URL goes here"
Set IE = New InternetExplorer

With IE
.Visible = True
.navigate URL
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
.document.Links(6).Click
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
End With

Set ieDoc = IE.document

TNTest = "5555551212"

While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend

With ieDoc.forms(0)
.Search.Value = TNTest
.submit
End With


End Sub


And here are what I hope are the relevant parts of the HTML


<BODY class="yui-skin-sam"><DIV id="doc3" class="yui-t1"><DIV id="hd">

<DIV id="bd">
<DIV id="yui-main">
<DIV class="yui-b">
<DIV class="yui-g">
<!-- 794px Workspace -->
<DIV id="_API_topmenu">
<DIV id="topmenu" name="topmenu">
</DIV>
</DIV>
<DIV id="_API_main">
<DIV id="main" name="main">
<FORM id="f1" name="f1" jQuery1363901810999="3">
Telephone Number or Subscriber Account: <INPUT id="SEARCH" class="required" name="SEARCH" validate="required:true" value="" /> <INPUT type="submit" jQuery1363901810999="4" value="Continue" />
</FORM>
</DIV>
</DIV>
</DIV>
</DIV>
</DIV><script>$(function(){$("#f1").validate({submitHandler:function(form){server.submit('PO_Manage_Reservati ons','FindSubscriber',form);},errorPlacement:function(error,element){},high light:function(element,errorClass){$('#'+element.id).addClass(errorClass);$ (element.form).find("label[for="+element.name+"]").addClass(errorClass);},unhighlight:function(element,errorClass){$('#'+ele ment.id).removeClass(errorClass);$(element.form).find("label[for="+element.name+"]").removeClass(errorClass);}});});</script>


I believe I may need to use the execScript method, but I'm unsure what I need to be calling, or if there is a better way. Any suggestions are much appreciated.

Using Office 2010 and IE 8. The code successfully places the telephone number in the Search box, but is unsuccessful when trying to submit the form.


<edited to add version info>

Treat
04-22-2013, 06:18 PM
I was able to find a way to submit this form using this code:


Set ElementCol = IE.document.getElementsByTagName("input")

For Each btnInput In ElementCol
If btnInput.Value = "Continue" Then
btnInput.Click
Exit For
End If
Next btnInput

If anyone know a way to get the data from the elements collection and call it directly rather than sending it through a loop everytime, that would be helpful.