VBA 将数据输入到 Jquery 表中以在站点上提交搜索



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

下面是表格div 的 html 片段。

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

还有一个带有控制台的页面屏幕截图,不幸的是我无法提供 URL,因为它是一个只能使用公司凭据访问的网站。有问题的提交页面。

<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>

无法访问该网站,很难说这肯定会起作用,但像这样的方法是实现您所追求的一种方法。

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
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

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

最新更新