-1
<input type="text" class="quantumWizTextinputPaperinputInput exportInput" jsname="YPqjbf"
autocomplete="off" tabindex="0" aria-label="Untitled question" 
aria-describedby="i.desc.608035577 i.err.608035577" 
name="entry.1790931838" value="" required="" dir="auto" data-initial-dir="auto" 
data-initial-value="" aria-invalid="true">

The above is the HTML code of the input box which I would like to automatically fill with VBS.

<span jsslot="" class="appsMaterialWizButtonPaperbuttonContent exportButtonContent"><span class="appsMaterialWizButtonPaperbuttonLabel quantumWizButtonPaperbuttonLabel exportLabel">Submit</span></span>

And the above is the code for the submit button.

On Error Resume Next
Const PAGE_LOADED = 4
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("https://docs.google.com/forms/d/e/1FAIpQLScOmcmtdsrm3RiX7FD9ur2eLPULL9ZulSzKxjG87BblRky7hQ/viewform")
objIE.Visible = True

WScript.Sleep(3000) 

IE.Document.getElementById("entry.1790931838").Value = "msdasdadm"

This is my code to auto-fill the form however I have not seemed to make it work. Also, I am not able to understand how to call the submit button and press that either.

Bhavesh Shaha
  • 717
  • 5
  • 21

1 Answers1

1

This should get you started...

On Error Resume Next

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("https://docs.google.com/forms/d/e/1FAIpQLScOmcmtdsrm3RiX7FD9ur2eLPULL9ZulSzKxjG87BblRky7hQ/viewform")
objIE.Visible = True

WScript.Sleep(3000) 

Dim input, inputs : Set inputs = objIE.document.getElementsByTagName("INPUT")
For Each input In inputs
    If ("text" = input.getAttribute("type")) Then
        input.value = "Just a test"
        Exit For
    End If
Next

Dim div, divs : Set divs = objIE.document.getElementsByTagName("DIV")
For Each div In divs
    If ("button" = div.getAttribute("role") And "M2UYVd" = div.getAttribute("jsname")) Then
        Call div.click()
        Exit For
    End If
Next

The Submit button is actually a parent DIV element with an associated JS onclick event handler defined. However, keep an eye on the jsname attribute, as the random name will most likely change between forms.

Hope this helps.

leeharvey1
  • 1,316
  • 9
  • 14
  • If I had multiple input blanks, how should I alter the For Loop? – Bhavesh Shaha Jun 03 '20 at 15:15
  • 1
    The **jsname** attribute will most likely be unique for every form element, including multiple input text blocks. Add conditional checks for each jsname, and populate the **input.value** accordingly. You can reference the code above (inside the divs For Loop) as an example for checking the jsname attribute. Enjoy. – leeharvey1 Jun 03 '20 at 16:47