好吧,我已经尝试了几个小时来使用VBA访问iframe内的搜索文本框,并且所有尝试都失败了。我已经在这里和其他网站上对此进行了研究,但似乎没有任何效果。作为前言,我的代码当前导航到我想要的网站并单击一个按钮,打开弹出的iFrame窗口。我需要访问iframe弹出框中的文本框并输入一个值。
以下是我尝试访问iFrame的代码部分(以及我注释失败的尝试)。
Public Sub FillOutOrder()
Call ie.document.parentWindow.execScript("AddItems()", "JavaScript") 'Opens up the iFrame pop-up
Dim iframe As Object
Set iframe = ie.document.frames("ModalContainerDivframe") 'Name of the iFrame
iframe.document.getElementById("spWin_SearchProducts").Value = "266050104" 'id Value of the iFrame Search Box
'^ This code is my last failed attempt. It just results in an error.
----------------------------------------------------------------------------
The code below are things I have tried that haven't worked.
' Set iDoc = ie.document.frames("ModalContainerDivframe").document
' For Each iFrame In iDoc
' If iFrame.ID = "spWin_SearchProducts" Then
' iFrame.value = "266050104"
' Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop
' Do Until ie.document.readyState = "complete": DoEvents: Loop
' Exit For
' End If
' Next
'iFrame source URL
'../common/popups/searchproducts2_container.cfm? Type=Master&SubType=BO&theId=6248538&dellocID=460418&showPriceQuantity=1&maskSave=1&_Key=5AF2B88C9056EF8DA4DFEAD048BDCDA3B7FC5D9B7B845D9A40D1942892D8AB460F83D1819EBA895E0CDF2A88DD6E96E9ABCE3CD454B8DFB9D208D2A9FCCD0581CC0CC09F2982851C989099D180EAC5D2DE1ECF9C91B410B6A89616987EEC57A1EB4CBB9E4ED4C15EAE459038464D48D217&_r=4.488391390158245
'Current Window URL
'https://www.oms.itradenetwork.com/2/buy/mo_details.cfm?theID=6248543&_Key=5678A0738A999603B58C17AF9151A8875F9F905AC600C1DBF6CBCAD5
End Sub
如果您对如何解决此问题有任何想法,请与我们联系。 谢谢!