提问人:Ruzaini Subri 提问时间:1/25/2020 更新时间:2/5/2020 访问量:236
Vba 控制 IE 中的弹出表
Vba to control pop up table in IE
问:
我想单击表格中的单选按钮并在下表的框中填写值
当我单击此文件链接之一时,将弹出该表。
然而,当这种情况发生时,我感觉很崩溃。
我的代码无法在该表上单击“确定”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>
谢谢
答:
0赞
Yu Zhou
1/27/2020
#1
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("rdbSeparatorCustom").Click
HTMLDoc.getElementById("TXT_CSV_COLUMN_SEPARATOR").Value = "test"
HTMLDoc.getElementById("rdbEnclosureCustom").Click
HTMLDoc.getElementById("TXT_CSV_COLUMN_ENCLOSURE").Value = "test"
HTMLDoc.getElementById("btnSubmit").Click
End Sub
评论
0赞
Ruzaini Subri
1/27/2020
VBA本身不会给出任何错误,但html中的函数似乎无法正常工作。我把html代码放在这里[dropbox.com/s/i0mwmeu06yxe1ux/html%20code%20of%20form.txt?dl=0]
0赞
Yu Zhou
2/5/2020
我使用您提供的 html 代码进行了测试,并将单选按钮中的 onclick 函数更改为 ,它可以很好地与上述 vba 代码配合使用。我认为问题是html中的函数无法工作,如果没有VBA就无法触发该功能,那么它当然不能用VBA触发。此外,您的VBA代码中是否有类型错误?我认为应该是.console.log
HTMLDocDoc
HTMLDoc
0赞
Yu Zhou
2/5/2020
此外,您应该注意弹出表是否在 iframe 中。如果它位于 iframe 中,则无法使用 直接访问对象。您应该首先到达 iframe,然后才能到达元素。有关详细信息,您可以参考此答案。docement.getElementById
评论