点击动作不做任何事 - IE模拟 [英] .Click action not doing anything - IE Simulation
问题描述
我正在尝试通过IE应用程序模拟与Google的交互,并通过DOM获取我需要的类,一切都很好,踩过代码,除了 .Click
不会导致崩溃但不执行任何操作的操作(页面无法导航) - 以下HTML代码和屏幕截图:
I'm trying to simulate the interaction with Google through the IE app and going through the DOM to get the classes I need and all is fine, stepping though the code, except the .Click
action which doesn't cause a crash but it doesn't do anything (page doesn't navigate) - Code and screenshot of HTML below:
Option Explicit
Private Sub Test_Automation()
Dim ie, doc, eInput, eButton, eButtons As Object
Dim sURL, sTest As String
Set ie = CreateObject("internetexplorer.application")
sURL = "https://www.google.co.uk/?gfe_rd=cr&ei=IpDvWK72LsjCaJCbjKAL&gws_rd=ssl"
sTest = "Test"
With ie
.Visible = True
.Navigate sURL
End With
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Set doc = ie.document
Set eInput = doc.getElementByid("lst-ib")
Set eButtons = doc.getElementsByTagName("input")
eInput.Value = sTest
For Each eButton In eButtons
If (eButton.getattribute("name") = "btnK") Then
eButton.Click
Exit For
End If
Next
End Sub
任何建议我做错了会很棒!
Any advise on what I'm doing wrong would be great!
推荐答案
你可以摆脱你的 For .. .Next
在底部循环并替换它以单击按钮:
You can get rid of your For...Next
loop at the bottom and replace it with this to click the button:
doc.forms(0).submit
0可以更改为另一个数字(例如1或2)单击其他按钮。如果页面上有多个可以点击的按钮,只需要一些试验和错误就可以找出哪个数字与你想要点击的按钮匹配。
The 0 can be changed to another number (such as 1 or 2) to click on a different button. If there are multiple buttons on a page that can be clicked on it will just take some trial and error to find out which number matches the button you want to click.
这篇关于点击动作不做任何事 - IE模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!