如何使用 MS Access VBA 单击此 HTML 代码(没有名称或 ID)中的提交按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20185709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I click the submit button in this HTML code (has no name or ID) with MS Access VBA
提问by user3030149
The button on this HTML page doesn't have a name or ID so I am unable to click it. I've scanned the previous questions but none are like this HTML that I can see. I've not included the whole page but this is the section with the button in it that i need to click.
此 HTML 页面上的按钮没有名称或 ID,因此我无法单击它。我已经扫描了之前的问题,但没有一个像我可以看到的 HTML。我没有包括整个页面,但这是我需要单击的带有按钮的部分。
I'm using VBA from MS Access 2010 to maniupulate IE v8. I'm still learning so apologies if it's easy (hope it is). as you can see the SUBMIT input type has no name or ID. thanks.
我正在使用 MS Access 2010 中的 VBA 来操作 IE v8。如果很容易(希望是),我仍在学习,所以很抱歉。如您所见,SUBMIT 输入类型没有名称或 ID。谢谢。
</div>
<div id="container">
<div class="group">
<div id="content">
<div class="banner">
<h2>Welcome</h2>
<div id="search-box">
<form method="get">
<label for="criteria">Search</label>
<input type="text" id="search" name="search" value="" maxlength="255" />
<input type="submit" class="button" value="Search" />
<p class="hint">Search by Order No. Service ID or Your reference ID</p>
</form>
回答by Pradeep Kumar
Use this:
用这个:
Dim htmlButton
Set htmlButton = WebBrowser1.Document.GetElementByID("search-box").GetElementsByTagname("Input")(1)
'' Test to see if we got the right element. (Comment out or remove this line later)
MsgBox htmlButton.Value
'' Click that button
htmlButton.Click
回答by CommonGuy
Maybe use something like this:
也许使用这样的东西:
Set tags = wb.Document.GetElementsByTagname("Input")
For Each tagx In tags
If tagx.value = "Search" Then
tagx.Click
Exit For
End If
Next
Where wb is the WebBrowser control.
其中 wb 是 WebBrowser 控件。