【问题标题】:VBA input data into Jquery table to submit a search on a siteVBA 将数据输入到 Jquery 表中以在网站上提交搜索
【发布时间】:2018-11-23 03:35:14
【问题描述】:

我试图弄清楚如何将数据输入到格式为 Jquery 表的输入框中。

下面是表格的div的html sn-p。

我不知道如何引用单元格,所以我可以输入一个字符串,然后告诉 VBA Tab 然后 Enter 提交字符串作为搜索。 这不是 VBA 方面的问题,而是我如何在 URL 本身中定义输入框的值,如果可以这样做,它将使整个过程更快。我对jquery格式没有任何经验。

还有一个打开控制台的页面截图,遗憾的是我无法提供网址,因为它是一个只能使用公司凭据访问的网站。 Submission Page in Question

<div id="params" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
    <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#params-fields">Fields</a></li>
    <li class="ui-state-default ui-corner-top"><a href="#params-json">JSON</a></li>
    <li class="ui-state-default ui-corner-top"><a href="#params-raw">Raw</a></li>
  </ul>
  <div id="params-fields" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
    <table>
      <tbody>
        <tr indent="0" name="expenseReceiptUri" parampropindex="0">
          <th><span class="paramLabel" style="left: 0px;">expenseReceiptUri</span></th>
          <td><span style="left: 0px;"><input type="text" placeholder="Uri (required)" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" style="color: rgb(153, 153, 153);"></span><span class="snowman"
              style="left: 0px;">☃</span></td>
        </tr>
        <tr>
          <th></th>
          <td><input type="button" value="Submit" id="submit" style="margin-top: 5px;"><span id="fields-notify" class="notification" style="display: none;"></span></td>
        </tr>
      </tbody>
    </table>
  </div>
  <div id="params-json" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"> </div>
  <div id="params-raw" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"> <textarea id="rawParams"></textarea><input type="button" value="Submit" id="submitRaw"><input type="button" value="Format" id="formatRaw"><input type="button" value="From Fields →" id="fromFields"><input type="button" value="← To Fields" id="toFields">
    <div
      style="height:25px;">
      <div id="raw-notify" class="notification" style="display: none;">$nbsp;</div>
  </div>
</div>
</div>

【问题讨论】:

    标签: jquery html vba


    【解决方案1】:

    如果无法访问该网站,很难说这肯定会奏效,但这样的方法是实现您所追求的一种方法。

    Public Sub enterData()
    
        'I'm assuming you already have an IE window
    
        'Find the Object
        Dim elements As Object
        Dim element  As Object
    
        'More about element selectors https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
        Set elements = IE.Document.getElementByID("params-fields").getElementsByClassName("ui-autocomplete-input")
    
        'Iterate and check if has the 'placeholder' property with the 'Uri (required)' value
        For Each element In elements
    
            'see https://www.w3schools.com/jsref/met_element_getattribute.asp
            If element.getAttribute("placeholder") = "Uri (required)" Then
                element.Value = "Something goes here"
                Exit For
            End If
    
        Next
    
    End Sub
    

    【讨论】:

    • 这和我前几天试过的方法差不多,原来问题是我是怎么打开IE的,而不是我怎么调用那个变量的。
    【解决方案2】:
    Dim objIE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim element As HTMLLinkElement
    Set objIE = New InternetExplorerMedium
    Dim b64 As String
    Dim stoper As Integer
    
      'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True
    
    'navigate IE to this web page (a pretty neat search engine really)
    objIE.navigate "https://website.com"
    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.READYSTATE <> 4: DoEvents: Loop
    objIE.Document.getElementsByClassName("ui-autocomplete-input")(0).Value = "submission value"
    Set objInputs = objIE.Document.getElementsByTagName("input")
    For Each element In objInputs
    If element.id Like "Submit" Then
    element.Click
    End If
    Next
    

    这是我的解决方案,这是一个 IE 调用错误,我更改了

    Set objIE = New InternetExplorer
    

    Set objIE = New InternetExplorerMedium
    

    这让我的状态等待工作,这反过来又让下面的其他东西工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      相关资源
      最近更新 更多