当从包含IFrame的HTA中引用IFrame对象时返回null

IFrame object returning null when referenced from HTA containing the IFrame

本文关键字:IFrame 对象 返回 null 引用 HTA 包含      更新时间:2023-09-26

我正在尝试使用HTA自动完成表单填写的重复任务。我正在打开网页到一个IFrame。第一页是登录页。我能够轻松访问该页的用户名和密码元素(显示在IFrame中),因此能够通过单击HTA中的按钮自动登录。但是现在,下一页包含一个文本框,我需要填充,然后再次单击按钮。现在,我在HTA中有一个按钮。当我单击此按钮时,我希望文本框应该填充我所提供的值。但相反,我得到这个错误,无法设置空引用的属性"值"。在使用警告显示此对象时,它显示'null'。我没有得到,为什么我能够引用登录页面上的元素,为什么不在内页。

下面是我的代码:
<html>
<head>
 <HTA:APPLICATION
     APPLICATIONNAME="HTA"
     SYSMENU="YES"
     NAVIGABLE="YES"
>
    <meta http-equiv="x-ua-compatible" content="ie=11">
    <title>HTA</title>
<script type="text/javascript">
    window.resizeTo(700,700);
</script>
<script type="text/javascript" >
function Start() {
var iframePage = document.getElementById("iframeid").contentDocument;
var userId = iframePage.getElementById("userid");
var passwd = iframePage.getElementById("pwd");
var form = iframePage.getElementById("login");
userId.value='uu';
passwd.value='pp';
form.submit();
}
function Show() { 
    document.getElementById("iframe").style.display = "block";
}
function FillRncntl() {
var iframePages = document.getElementById("iframeid").contentDocument;;
var runcntl = iframePages.getElementById("PRCSMULTI");
runcntl.value='test';
}
</script>
</head>
 <body> 
        <form class="form" name="form">
                <input class="links" type="button"  value="Show PIA" onclick="Show();" /> 
                <input class="links" type="button"  value="Login" onclick="Start();" /> 
                <input class="links" type="button"  value="Enter Runcontrol" onclick="FillRncntl();" />
        </form> 
        <br>
        <div class="iframe" id="iframe" style="display:none">
        <iframe application="no" src="www.xyz.com" width="600" height="600" id="iframeid"> 
        </div>
 </body> 
 </html>

-Show PIA按钮显示登录页面。工作正常

-Login按钮用于自动登录。工作正常

-Enter Runcntl按钮用于填充某些文本框。不能正常工作

这不仅仅是与这个文本框,我有同样的问题与其他元素从这个页面以及。

PS:这是Peoplesoft的内网网站。

PeopleSoft内容包含在iFrame本身中,因此您需要获取targetContent iFrame并在其中搜索元素。

初始PeopleSoft登录页面不显示在iFrame中。

我更改了最后一个元素ID,以便这将在组件上工作:PeopleTools->Process Scheduler->System Process Requests

function FillRncntl() {
   var iframePages = document.getElementById("iframeid").contentDocument;
   var targetContent = iframePages.getElementById("ptifrmtgtframe").contentDocument;
   var runcntl = targetContent.getElementById("PRCSRUNCNTL_RUN_CNTL_ID");
   runcntl.value='test';
}