填写Internet Explorer输入框 [英] Filling Internet Explorer inputbox
问题描述
我读了这么多答案我的问题,但不知何故如果我试图模仿我看到的,我仍然无法做我需要的。
I read so many answers to my problem but somehow if I try to "mimic" what I see, I still am not able to do what I need.
问题很简单:在打开的IE页面上填写一个输入框。
The problem is very simple: fill an inputbox on an opened IE page.
结果:代码卡住了 getelementbyid
显示运行时错误424(需要对象)。
Result: the code gets stuck on the line with getelementbyid
showing runtime error 424 (object required).
Private Sub AddInfoFromIntranet()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
Application.SendKeys "{ESC}" ' I need this to ignore a prompt
With ie
.Visible = True
.navigate "{here goes the address of my website}"
Do Until Not .Busy And .readyState = 4
DoEvents
Loop
.document.getelementbyid("Nachnamevalue").Value = "{here goes whar I want to insert}"
End With
Set ie = Nothing
End Sub
Internet Explorer库自然导入我的意思是internetexplorer.application不起作用。
Internet Explorer libraries were naturally imported (otherwise the "internetexplorer.application" wouldn't work.
我觉得我想填写的字段被称为Nachnamevalue,就像我今天早上学到的一样
I am positive that the field I want to fill is called "Nachnamevalue" as from what I learned this morning taking a look around the internet.
我的网页的HTML代码(只有有趣的部分)如下所示:
The html code of my webpage (only the interesting piece) looks like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
'{here there are info on the style, which i'm gonna ignore}
</style>
</head>
<body bgcolor="#ffffcc"><table width="1000"><tbody><tr><td>
<form name="Suchform" action="index.cfm" method="get" target="bottom_window">
Nachname:
<select name="Nachnamepulldown" class="font09px" onchange="wait_and_search()">
<option value="BEGINS_WITH">beginnt mit
<option value="EQUAL">ist
<option value="CONTAINS">enthält
</option></select>
<input name="Nachnamevalue" onkeyup="wait_and_search()" type="text" size="8">
Abteilung:
<select name="Abteilungpulldown" class="font09px" onchange="wait_and_search()">
<option value="BEGINS_WITH">beginnt mit
<option value="EQUAL">ist
<option value="CONTAINS">enthält
</option></select>
<input name="Abteilungvalue" onkeyup="wait_and_search()" type="text" size="3">
<input name="fuseaction" type="hidden" value="StdSearchResult">
<input type="submit" value="suchen">
<script language="JavaScript" type="text/JavaScript">
document.Suchform.Nachnamevalue.focus();
</script>
</form>
</td></tr></tbody></table></body>
</html>
还有(我不知道是否可以帮助)一个嵌入式
There is also (I don't know if it can help) an "embedded" javascript that brings results of a search up every time at least 2 characters in the "Nachnamevalue" inputbox are written.
我在做什么错?
编辑:
当我尝试执行Sub一步一步,我得到以下内容:
When I try to execute the Sub step-by-step, I get the following:
设置Doc = ie.document
? Doc
[object HTMLDocument]
(在观察列表中,它是一个没有任何变量的对象)
? Doc [object HTMLDocument] ( in the watchlist it is an object without any variables inside )
推荐答案
GetElementById
通过其 id
属性获取元素,但 Nachnamevalue
是 名称
属性的值。
GetElementById
gets an element by its id
attribute, but "Nachnamevalue"
is the value of the name
attribute.
要使用名称:
.document.Forms("Suchform").Elements("Nachnamevalue").value = "xxx"
这篇关于填写Internet Explorer输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!