Vba来控制IE中的弹出表

问题描述 投票:0回答:1

我想单击表中的单选按钮并在下表中的框中填写值

enter image description here

当我单击此文件链接之一时,表格将弹出。但是,发生这种情况时,我的HTMLdocument(HTMLDoc)感觉像坏了。我的代码无法在该表上单击“确定”

这是我的代码

Set IE2 = CreateObject("InternetExplorer.Application")
apiShowWindow IE2.hwnd, SW_MAXIMIZE

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE2.Visible = True
IE2.Visible = False
IE2.Visible = True

'Define URL
URL = "https://dgspj-prod.ptcmanaged.com/intellicus/core/SavedReportList.jsp?CATEGORYID="

'Navigate to URL
IE2.navigate URL

' Wait while IE loading...
Do While IE2.readyState = 4: DoEvents: Loop   'Do While
Do Until IE2.readyState = 4: DoEvents: Loop   'Do Until

Set HTMLDoc = IE2.document

    'below not fulfilled in table
    HTMLDoc.getElementById("rdbSeparatorCustom").Click
    HTMLDoc.getElementById("TXT_CSV_COLUMN_SEPARATOR").Value = "~"
    HTMLDoc.getElementById("rdbEnclosureCustom").Click
    HTMLDoc.getElementById("TXT_CSV_COLUMN_ENCLOSURE").Value = ""

    HTMLDoc.querySelector("input[value='Ok']").Click 'not work
    HTMLDocDoc.getElementById("btnSubmit").Click 'not work too

这里是IE HTML

<LABEL class=option-label style="MARGIN-LEFT: 42px"><INPUT onclick='fnEnableDisableControls(this,"ENCLOSURE","csv");' id=rdbEnclosureCustom type=radio value=CUSTOM name=CSV_COLUMN_ENCLOSURE_TYPE>Custom</LABEL>
<DIV class=win-btn-wpr><INPUT onclick=fnSetIsDirty();fnSubmit(); id=btnSubmit class="cssButton btn-blue" type=button value=Ok name=btnSubmit> <INPUT onclick=fnHideDiv() id=btnCancel class=cssButton type=button value=Cancel name=btnCancel> </DIV>  

谢谢

vba internet-explorer dom
1个回答
0
投票

似乎VBA代码可以很好地与所提供的HTML代码一起使用。运行VBA代码以及在哪一行发生错误时,是否有任何错误?您能否提供可以重现此问题的HTML代码?我使用以下VBA代码进行了测试,它可以单击单选按钮和“提交”按钮:

Sub LOADIE()
Set IE2 = CreateObject("InternetExplorer.Application")

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE2.Visible = True

'Define URL
URL = "http://test page"

'Navigate to URL
IE2.navigate URL

' Wait while IE loading...
Do While IE2.readyState = 4: DoEvents: Loop   'Do While
Do Until IE2.readyState = 4: DoEvents: Loop   'Do Until

Set HTMLDoc = IE2.document

HTMLDoc.getElementById("rdbEnclosureCustom").Click

HTMLDoc.getElementById("btnSubmit").Click

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.