我的这个问题已经持续了好几个星期我正在实习,我所在的部门负责让我在他们的系统中自动搜索。我已经知道getElements是如何工作的,这是你在inspect元素中可以看到的:
<DOCTYPE html PUBLIC "=..../frameset.dtd>
<html xmlns=...>
<head>
<frameset style>
<Frame name = "Frame1" src = "Frame1.aspx">
<Frame name = "Frame2" src = "Frame2.aspx">
|
V
<!DOCTYPE html PUBLIC ".....transitional.dtd">
<html xmlns=...>
<head>
<body>
<form name = "form1" id ="form1">
<div id="appiDIVA">
<iframe name = appiFrame class="aFrame" src="Router.aspx">
<!DOCTYPE html PUBLIC "-...Frameset.dtd">
<html xmlns=...>
<head>
<frameset style = "">
<frame name = "LeftPage" id = "LeftPage">
<!DOCTYPE html PUBLIC "-...something.dtd">
<html xmlns=...>
<head>
<body class = "left frame">
<form id="frmleftForm action = LeftFrame.aspx" method = "post">
<div>
<script type = "javascript">
<script src = ".....">
.
.
.
<div class = "searchbox">
<select name = ctlSearch$.. id = ctlSearch_... onchange = javascript... >
***<a tabindex="2" class="find" id = searchbutton onclick = "return......." href = "javascript:_..........">***
<div id ="ctlsearchupdate">
<span id="ctlsearchtxtfind" style="...">
***<input name ="ctlsearch$findthis" tab index="1" id = ctlsearch_" accesskey="4" type="text" maxlength="25" autcomplete="off">***
我需要访问/更改的元素是代码中带星号的元素。问题是我需要输入或点击的那些元素位于 NESTED / EMBEDDED FRAME
中我做了很多事情,比如检查Textbox1.text = IE.document.body.innerHTML
中存在的元素,当我这样做时它只显示:
<frame name = "Frame1" src = "Frame1.aspx" frame border = "0" noresize="noresize">
<frame name = "Frame2" src = "Frame2.aspx" frame border = "0" noresize="noresize">
然后我研究了代码:
Textbox1.Text = IE.document.getElementsById("ContentFrame").contentDocument.DocumentElement.innerHTML
然后显示元素直到<iframe name = appiFrame class="aFrame" src="Router.aspx">
没有显示其内容或其下方的任何内容。
如上面的代码所示,元素在frame2中,我已经被困了几个星期,至于如何至少输入一个值到文本框。
然后我这样做了:
PrivateSub CommandButton1_Click()
Dim HTMLdoc As HTMLDocument
Dim IE As InternetExplorerMedium
Set doc = IE.document.frames.frames(1).document.getElementsByName("appiFrame")(0)
If(doc Is Nothing) Then
MsgBox("Element Not Detected")
Else
MsgBox("Detected")
TextBox1.Text = IE.document.body.innerHTML
MsgBox(doc)
End If
End Sub
这里发生的是 iFrame 现在通过弹出 [objectHTMLIFrameElement] 的消息检测到,但innerHTML仍然只显示两个框架集,我被困住了,因为我可以前进或挖掘元素。如果我能至少伸出援助之手,我将不胜感激!