[英]Switch to web iframe and fill drop-downs using excel vba
我有下面的代码打开网页,调用Java脚本功能。 接下来我想要的是:切换到名为displayFrame
iframe。 然后在下拉菜单中选择选项。 目前,我无法切换到iframe并在表单中添加值。 我对此并不陌生,所以需要您的帮助。
码:
Option Explicit
Sub Fillform()
Dim URL As String
Dim ie, frm As Object
Dim FF As Integer
Dim wb As WebBrowser
Dim objElement As Object
Dim objCollection As Object
Dim button, goBtn As Object
Dim HTML As HTMLDocument
Dim Dropdown As IHTMLElement
Dim dropOption As IHTMLElement
Dim HTMLdoc As HTMLDocument
Dim link As HTMLLinkElement
Dim theFrame As HTMLIFrame
Dim Frame1, Frame2 As HTMLIFrame
On Error Resume Next
Application.ScreenUpdating = False
URL = "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=a3rgcw&g_session_id=7302840" 'for TEST
Set ie = CreateObject("Internetexplorer.Application")
ie.Visible = True
ie.Navigate URL
Do Until ie.ReadyState = 4
DoEvents
Loop
' Call java-script function
ie.Navigate ("javascript:parent.gotoCreate('advanced');")
Do Until ie.ReadyState = 4
DoEvents
Loop
Set theFrame = HTMLdoc.frames(0)
Set HTML = ie.Document
ie.Document.all.Item("product_application").Value = "NX"
ie.Document.getElementById("textInputField").Value = "N/A"
Set Dropdown = HTML.getElementById("product_application")
For Each dropOption In Dropdown.getElementsByTagName("option")
If dropOption.innerText = "Design" Then
Dropdown.Value = dropOption.Value
Exit For
End If
Next dropOption
' or may be this way to select drop-down
ie.Document.getElementById("priority_selection").Value = "Design"
iframe html代码:
<frame name="displayFrame" src="/webpr/webpr.php?objtype=MyWebPR&g_userid=a3rgcw&g_session_id=7321635&g_devmode=&g_dbname=">
如何获取IFrame文档的提示-尝试遵循以下逻辑(未经测试) :
'for early binding
Dim IEApp As InternetExplorer
Set IEApp = New InternetExplorer
Dim docHTML As HTMLDocument
Set docHTML = IEApp.document
Dim webIFrame As Object 'As HTMLIFrame
'try with any of this lines to get to IFrame
Set webIFrame = docHTML.getElementsByTagName("iframe")(0) 'your index if not 0
Set webIFrame = = docHTML.frames(0)
'and to get to document:
Dim docIFrameHTML As HTMLDocument
set docIFrameHTML = webIFrame.document
'next you could try to fill your forms...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.