我是一个新手,我正在尝试通过VBScript网站http://www.cra-arc.gc.ca/esrvc-srvce/tx/bsnss/pdoc-eng.html在excel中自动计算一些工资。我已经试着弄清楚这件事好几天了,但没什么好结果。我想我的问题很简单:我正在尝试点击上面网站页面底部的“我接受”按钮。
我写的代码如下,但对于下面的代码,我不知道如何实际单击按钮。无论我怎么尝试,我总是在这里得到一个错误。
objIE.Application.document.getElementById("??????").Click下面的HTML代码没有ID。我也尝试过各种其他的东西,比如getElementByType,getElementByValue,但都没有成功
VBScript
Sub test()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Application.Visible = True
objIE.Application.navigate "http://www.cra-arc.gc.ca/esrvc-srvce/tx/bsnss/pdoc-eng.html"
Do While objIE.Application.Busy Or _
objIE.Application.readyState <> 4
DoEvents
Loop
objIE.Application.document.getElementById("??????").Click
Do While objIE.Application.Busy Or _
objIE.Application.readyState <> 4
DoEvents
Loop
End SubHTML代码
<div class="alignCenter">
<input type="button" title="I accept - Begin the calculation" value="I accept" onclick="parent.location='https://apps.cra-arc.gc.ca/ebci/rhpd/startLanguage.do?lang=English'" />
<input type="button" title="I do not accept - Return to Payroll" value="I do not accept" onclick="parent.location='/tx/bsnss/tpcs/pyrll/menu-eng.html'" />
</div>如果有人能帮忙,我会很感激的。
谢谢,
马太福音
发布于 2013-02-12 08:07:47
注意,VB/VBA的DoEvents函数在VBScript中不可用。然而,这里是有效的代码。
Call test
Sub test()
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.cra-arc.gc.ca/esrvc-srvce/tx/bsnss/pdoc-eng.html"
Do While .Busy Or .readyState <> 4
WScript.Sleep 50
Loop
Set oInputs = .Document.getElementsByTagName("input")
For Each elm In oInputs
If elm.Value = "I accept" Then
elm.Click
Exit For
End If
Next
Do While .Busy Or .readyState <> 4
WScript.Sleep 50
Loop
End With
End Subhttps://stackoverflow.com/questions/14817436
复制相似问题