Javascript 无法在网站框架内的InputBox中写入

Javascript 无法在网站框架内的InputBox中写入,javascript,vba,internet-explorer,iframe,web-scraping,Javascript,Vba,Internet Explorer,Iframe,Web Scraping,这篇文章如下 我们试图隔离这个问题,但似乎我无法(可能是因为页面中有JavaScript?——请看另一篇文章)正确寻址到我想要的特定输入框。我写的代码是: Sub AddInfoFromIntranet() Dim Ie As SHDocVw.InternetExplorer Dim Doc As MSHTML.HTMLDocument Dim Elements As MSHTML.IHTMLElementCollection Set Ie = New SHDocVw.Interne

这篇文章如下

我们试图隔离这个问题,但似乎我无法(可能是因为页面中有JavaScript?——请看另一篇文章)正确寻址到我想要的特定输入框。我写的代码是:

Sub AddInfoFromIntranet()

Dim Ie As SHDocVw.InternetExplorer
Dim Doc As MSHTML.HTMLDocument
Dim Elements As MSHTML.IHTMLElementCollection

    Set Ie = New SHDocVw.InternetExplorer
    With Ie
        .navigate "[HERE GOES MY WEBSITE]"
        .Visible = True

        Do Until Not .Busy And .readyState = 4
            DoEvents
        Loop

        Set Doc = .document
        Set Elements = Doc.getElementsByName("Nachnamevalue")

        .Quit
    End With

    Set Ie = Nothing

End Sub
“Nachnamevalue”是网页“顶部窗口”框架中包含的元素的名称:

上面的图片是我打开我想要的地址,按F12键,然后在想要的输入框中点击“选择项目”项目得到的。 一开始,页面只是一堆Java脚本(打开页面-F12并复制DOM explorer的内容)

现在,如果我想看看我的“Elements”变量是什么,我得到的对象基本上是空的

如果我写:

Set Elements = Doc.getElementsByName("top_window")
有东西要找。 不幸的是,我正在处理一个内部网页,所以我无法向您提供地址

编辑:完整javascript

<html><head><script language="JavaScript">

    function NewWindow(window_name){
        var detail; 
        detail = open(window_name,"detail","dependent,resizable,screenX=50,screenY=50,width=400,height=400");
        detail.focus();
    }

    function NewWindowScroll(window_name){
        var detail; 
        detail =    open(window_name,"detail","dependent,scrollbars,resizable,screenX=50,screenY=50,width=600,height=500");
        detail.focus();
    }


    function NewWindowSize(window_name,w,h){
        var detail, windata;
        detail = open(window_name,"detail","dependent,scrollbars,resizable,screenX=250,screenY=250,width=" + w + ",height=" + h);
        detail.focus();
    }

    function MiniWindow(window_name){
        var detail; 
        detail = open(window_name,"miniwindow","dependent=no,resizable=yes,screenX=0,screenY=0,width=800,height=20");
        detail.focus();
    }



    last_timer="new"    

    function DoSearch(){
        document.Suchform.submit() 
    }

    function wait_and_search(){ 
        clearTimeout(last_timer)
        last_timer = window.setTimeout("DoSearch()", 400);
    }


    function check_kpeq(this_handle){
        equ_string = this_handle.value;
        text = equ_string.replace(/[^0-9A-Za-z\-]/g,"");    
        zahlen = text.split(/[\-\/]/);              
        if (zahlen.length != 4) {falsches_equ_format(this_handle);  return false;}

        fill="000";

        Zahl_1   = fill + zahlen[0];    
        Zahl_1 = Zahl_1.slice(Zahl_1.length-3)

        Zahl_2   = fill + zahlen[1];    
        Zahl_2 = Zahl_2.slice(Zahl_2.length-1)

        Zahl_3   = fill + zahlen[2];    
        Zahl_3 = Zahl_3.slice(Zahl_3.length-2)

        Zahl_4 = zahlen[3];

        this_handle.value = (Zahl_1 + "-" + Zahl_2 + "-" + Zahl_3 + "-" + Zahl_4);

        return true;      
    }


    function check_anab(this_handle){
        anab_string = this_handle.value;
        if (anab_string == "") {return true;} 
        text = anab_string.replace(/[^0-9\-]/g,""); 
        zahlen = text.split(/[\-\/]/);              
        if (zahlen.length != 3) {falsches_anab_format(this_handle);  return false;}

        fill="000";

        Zahl_1   = fill + zahlen[0];
        Zahl_1 = Zahl_1.slice(Zahl_1.length-2)

        Zahl_2   = fill + zahlen[1];    
        Zahl_2 = Zahl_2.slice(Zahl_2.length-2)

        Zahl_3   = fill + zahlen[2];    
        Zahl_3 = Zahl_3.slice(Zahl_3.length-3)


        this_handle.value = (Zahl_1 + "-" + Zahl_2 + "-" + Zahl_3 );

        return true;      
    }


    function falsches_anab_format(this_handle) {
        t1 = "Ung?ltiges Format f?r HVT AN/AB:  >>  " + this_handle.value + "  <<\n\n";
        t2 = "Nur 3 Zahlen mit '-' als Trennzeichen erlaubt\n\n";
        t3 = "Z.B.: '01-08-001'"
        alert(t1 + t2 + t3);
        this_handle.focus();
    }


    function falsches_equ_format(this_handle) {
        t1 = "Ung?ltiges Format f?r EQU:  >>  " + this_handle.value + "  <<\n\n";
        t2 = "Nur 4 Zahlen mit '-' als Trennzeichen erlaubt\n\n";
        t3 = "Z.B.: '003-2-60-7'"
        alert(t1 + t2 + t3);
        this_handle.focus();
    }


    function check_form(){

        if (check_kpeq(document.editanlagedata.KPEQ)        == false){return false};        
        if (check_anab(document.editanlagedata.HVAN)        == false){return false};        
        if (check_anab(document.editanlagedata.HVAB)        == false){return false};        
        return true;
    }

</script>


    <title>Telefon-Suche</title>    
    <link title="Telefonsuche - Abteilung" href="[XML FILE REGARDING WEBPAGE].xml" rel="search" type="application/opensearchdescription+xml">
    <link title="Telefonsuche - Name" href="[XML FILE REGARDING WEBPAGE].xml" rel="search" type="application/opensearchdescription+xml">
</head>
<!-- frames -->
<frameset rows="90,*" bordercolor="#ffffcc" frameborder="0">
    <frame name="top_window" src="index.cfm?fuseaction=StdSearchForm" scrolling="No">
    <frame name="bottom_window" src="index.cfm?fuseaction=ShowStartpage" scrolling="Auto">
</frameset><noframes></noframes>

函数NewWindow(窗口名称){
var细节;
细节=打开(窗口名称,“细节”,“相关,可调整大小,屏幕X=50,屏幕Y=50,宽度=400,高度=400”);
detail.focus();
}
函数NewWindowScroll(窗口名称){
var细节;
细节=打开(窗口名称,“细节”,“相关,滚动条,可调整大小,screenX=50,screenY=50,宽度=600,高度=500”);
detail.focus();
}
函数NewWindowSize(窗口名称,w,h){
var详细信息,windata;
细节=打开(窗口名称,“细节”,“相关”,滚动条,可调整大小,屏幕X=250,屏幕Y=250,宽度=“+w+”,高度=“+h”);
detail.focus();
}
功能小窗口(窗口名称){
var细节;
细节=打开(窗口名称,“迷你窗口”,“依赖项=否,可调整大小=是,屏幕X=0,屏幕Y=0,宽度=800,高度=20”);
detail.focus();
}
last_timer=“新建”
函数DoSearch(){
document.Suchform.submit()
}
函数wait_和_search(){
clearTimeout(最后一个计时器)
last_timer=window.setTimeout(“DoSearch()”,400);
}
功能检查\u kpeq(此\u手柄){
eq_字符串=此句柄.value;
text=eq_字符串。替换(/[^0-9A-Za-z\-]/g,”);
zahlen=text.split(/[\-\/]/);
如果(zahlen.length!=4){falsches_eq_格式(此句柄);返回false;}
fill=“000”;
Zahl_1=填充+zahlen[0];
Zahl_1=Zahl_1.切片(Zahl_1.长度-3)
Zahl_2=填充+zahlen[1];
Zahl_2=Zahl_2.切片(Zahl_2.长度-1)
Zahl_3=填充+zahlen[2];
Zahl_3=Zahl_3.切片(Zahl_3.长度-2)
Zahl_4=zahlen[3];
这个句柄值=(Zahl_1+“-”+Zahl_2+“-”+Zahl_3+“-”+Zahl_4);
返回true;
}
功能检查(此手柄){
anab_string=此_handle.value;
if(anab_string==“”){return true;}
text=anab_字符串。替换(/[^0-9\]/g,”);
zahlen=text.split(/[\-\/]/);
如果(zahlen.length!=3){falsches_anab_格式(此句柄);返回false;}
fill=“000”;
Zahl_1=填充+zahlen[0];
Zahl_1=Zahl_1.切片(Zahl_1.长度-2)
Zahl_2=填充+zahlen[1];
Zahl_2=Zahl_2.切片(Zahl_2.长度-2)
Zahl_3=填充+zahlen[2];
Zahl_3=Zahl_3.切片(Zahl_3.长度-3)
这个句柄值=(Zahl_1+“-”+Zahl_2+“-”+Zahl_3);
返回true;
}
函数falsches_anab_格式(此句柄){

t1=“Ung?ltiges Format f?r HVT AN/AB:>>“+此句柄.value+”“+此句柄.value+”您遇到的问题是,当您的目标输入框“Nachnamevalue”位于
IFrame
内时,IE必须首先导航到目标页面,然后再导航到IFrame

如果没有出现到
IFrame
的导航,则DOM不包含
IFrame
内部的元素,这就是它不工作的原因。HTH

(示例代码使用位于我的电脑上的文件,因此将url替换为来自intranet的实际url,并将“main.html”的名称替换为实际页面的名称。)

top\u window.HTML的示例HTML

<html>
<head>
<title></title>
</head>
<frameset cols="" rows="">
  <frame name="top_window" src="top_window.html" />
</frameset>
<noframes>
<!-- no frames content here -->
</noframes>
</html>
<html>
<head>
<title></title>
</head>
<body bgcolor="#ffffcc">
  <form name="Suchform" action="index.cfm">
    Nachname:
    <input name="Nachnamevalue" type="text" size="8">
  </form>
</body>
</html>

纳希纳姆:

添加javascript代码please@Noldor130884请将观察者的图片添加到对象中,如您在聊天中所示,以向其他用户显示内容。在目标中,我应该参考哪个库来使用SHDocVw和MSHTML对象?“Microsoft Internet控件”和“HTML对象库”
<html>
<head>
<title></title>
</head>
<body bgcolor="#ffffcc">
  <form name="Suchform" action="index.cfm">
    Nachname:
    <input name="Nachnamevalue" type="text" size="8">
  </form>
</body>
</html>