【问题标题】:Submitting Google Form with VBS使用 VBS 提交 Google 表单
【发布时间】:2020-06-03 21:23:59
【问题描述】:
<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">

以上是我想用VBS自动填充的输入框的HTML代码。

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

以上是提交按钮的代码。

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"

这是我自动填写表单的代码,但我似乎没有让它工作。另外,我也无法理解如何调用提交按钮并按下它。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    这应该让你开始......

    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
    

    提交按钮实际上是一个父 DIV 元素,其中定义了一个关联的 JS onclick 事件处理程序。但是,请注意 jsname 属性,因为随机名称很可能会在表单之间发生变化。

    希望这会有所帮助。

    【讨论】:

    • 如果我有多个输入空白,我应该如何更改 For 循环?
    • jsname 属性很可能对于每个表单元素都是唯一的,包括多个输入文本块。为每个 jsname 添加条件检查,并相应地填充 input.value。您可以参考上面的代码(在 divs For Loop 内)作为检查 jsname 属性的示例。享受吧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2013-04-30
    相关资源
    最近更新 更多