PDA

View Full Version : Check if a text box exists in a webpage and if so then run code.



cfernand74
08-10-2014, 10:25 PM
Having issues with several of the vendors i work for. They have a web form that i complete by transferring data from excel into there webpage. This vendor has several web forms that look similar but have additional questions(text boxes) that differ from form to form and need filling out.
What i want to do is check/test if webpage hold that text box and if so then run my code.


Sample web code for a text box i want to check for on a web page and if it exist on web page then run the code below:
<input name="ext_color" class="textfield required" id="ext_color" type="text" maxlength="15" value="Baige">

This is how i input data into this text box:
IE.Document.getElementsByName("ext_color")(0).Value = Range("aj54")

What normally happens is this text box is not on all forms that i complete, so i want to eliminate/bypass executing the code by implementing an If..Then statement for when the text box is not included on the webpage form.


thanks in advance.

Aussiebear
08-11-2014, 01:54 AM
Do you know what the text box is called, or is it the only one on the web page?

cfernand74
08-11-2014, 05:58 PM
Do you know what the text box is called, or is it the only one on the web page?

This code holds the text box:
<input name="ext_color" class="textfield required" id="ext_color" type="text" maxlength="15" value="Baige">

name="ext_color" is the text box

mancubus
08-12-2014, 12:11 AM
below may give you an idea:



Dim txtColor As Object
On Error Resume Next
Set txtColor = IE.Document.getElementsByName("ext_color")
If Not txtColor Is Nothing Then
txtColor.Value = Range("AJ54")
End If
On Error GoTo 0

snb
08-12-2014, 12:30 AM
or


On Error Resume Next
IE.Document.getElementsByName("ext_color").Value=Range("AJ54")