PDA

View Full Version : Problem with IE automation - getElementsByTagName



Ken Crawford
07-05-2013, 05:42 PM
Greetings to all, :hi:

I am using vb code to import IE data to userform (textboxes), then when I fill some texboxes I want them to be sent to IE forms.

But I have a problem with the export to IE.

Here is a part of HTML code of the website :


<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
<nobr>Customer Name</nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
<!-- FieldName="Customer"
FieldInternalName="Customer_x0020_Name"
FieldType="SPFieldText"
-->
<span dir="none">
<input name="ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl03$ctl00$ctl0 0$ctl04$ctl00$ctl00$TextField" type="text" value="Microsoft" maxlength="100" id="ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl03_ctl00_ctl0 0_ctl04_ctl00_ctl00_TextField" title="Customer Name" class="ms-long" /><br>
</span>

</TD>
</TR>

<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
<nobr>Description<span class="ms-formvalidation"> *</span></nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
<!-- FieldName="Description"
FieldInternalName="Comment"
FieldType="SPFieldNote"
-->
<span dir="none">
<span dir="ltr">
<textarea name="ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl08$ctl00$ctl0 0$ctl04$ctl00$ctl00$TextField" rows="6" cols="20" id="ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl08_ctl00_ctl0 0_ctl04_ctl00_ctl00_TextField" title="Description" class="ms-long" dir="none">EXAMPLE DESCRIPTION</textarea>
<input name="ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl08$ctl00$ctl0 0$ctl04$ctl00$ctl00$TextField_spSave" type="HIDDEN" id="ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl08_ctl00_ctl0 0_ctl04_ctl00_ctl00_TextField_spSave" />
</span>
</span>


</TD>
</TR>


And here is vb code I created :



Dim objIE As Object
Dim inputCollection As Object
Dim inputElement As Object


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

objIE.Navigate "address"


Do While objIE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop


Set inputCollection = objIE.Document.getElementsByTagName("input")
For Each inputElement In inputCollection
If inputElement.getAttribute("title") = "Customer Name" Then
objIE.Document.getElementById("ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl03$ctl00$ctl0 0$ctl04$ctl00$ctl00$TextField").Value = TextBox4.Value
Exit For
End If
Next inputElement


Set inputCollection = objIE.Document.getElementsByTagName("textarea")
For Each inputElement In inputCollection
If inputElement.getAttribute("title") = "Description" Then
objIE.Document.getElementById("ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl03$ctl00$ctl0 0$ctl04$ctl00$ctl00$TextField").Value = TextBox5.Value
Exit For
End If
Next inputElement

The problem is I have no idea how to make the script correctly allocate textbox values to the forms in IE, they have the same id's in the source code so there may be a conflict here.
I defined getElementsByTagName for each of them separately but it still is not working:(

Please help. Thanks in advance!