0
    Dim IE As InternetExplorer
    Set IE = New InternetExplorer
    Dim hDocument As MSHTML.HTMLDocument
    Dim hElementCollection As MSHTML.IHTMLElementCollection
    Dim hInputElement As MSHTML.htmlInputElement

    IE.Visible = True

    Dim url As String
    url = "www.blah.com"

    IE.Navigate url

    Call SleepIE(IE)
    PauseApp 3

    Dim xSom, xFrame As Object

'这是检查原始链接是否导致登录页面,如果是则登录,否则重定向

If IE.LocationURL = url Then
Set xFrame = IE.Document.getElementById("infoView")
        PauseApp 3 ' pausing application for 3 seconds for everything to load
        Do While True
        xFrame.contentWindow.Document.getElementById("username").Value = "username"
         If Err.Number = 0 Then
                Exit Do
            ElseIf Err.Number > 0 And Err.Number <> 91 Then
                Exit Function
            End If
            Err.Clear
        Loop

        Do While True
        xFrame.contentWindow.Document.getElementById("password").Value = "password"
         If Err.Number = 0 Then
                Exit Do
            ElseIf Err.Number > 0 And Err.Number <> 91 Then
                Exit Function
            End If
            Err.Clear
        Loop
        xFrame.contentWindow.Document.Forms(0).submit
    End If

    PauseApp 3
    Call SleepIE(IE) ' awaiting ie ready state

'这是我卡住的地方'我试图为“ListingURE_searchText”赋值,下面不起作用

        Set hElementCollection = IE.Document.frames("mainFrameSet").Document.frames("dataFrame").Document.frames("dataFrameSet").Document.frames("workspaceFrameSet").Document.all
        For Each hInputElement In hElementCollection
            If hInputElement.getAttribute("id") = "ListingURE_searchText" Then
            hInputElement.Value = "555"
            End If
        Next hInputElement

我也试过

    Set hElementCollection = hDocument.getElementsByTagName("INPUT")
        For Each hInputElement In hElementCollection
            If hInputElement.getAttribute("id")
               hInputElement.Value = "test"
            End If
        Next hInputElement

blow 是 20 页长的页面源代码的简短版本

<head>
<frameset id="mainFrameSet" rows="*">
<frame id="headerPlusFrame" scrolling="no" marginwidth="0" marginheight="0"     src="../listing
<iframe id="dataFrame"
<html>
<head>
<frameset id="dataFrameSet" rows="*,20">
<frameset id="centerFrameset" cols="*,0">
<frame id="workspaceFrame" frameborder="0" border="0" framespacing="2"    title="Workspace" src="workspace.do" name="workspaceFrame">
<html>
<head>
<frameset id="workspaceFrameSet" class="panelFrame" border="0" framespacing="0"     frameborder="0" rows="18,*">
<frame id="workspaceHeaderFrame" scrolling="no" noresize="" marginwidth="0"  marginheight="0" src="workspaceHeader.do?title=" title="Workspace Header" name="workspaceHeaderFrame">
<frame id="workspaceBodyFrame" noresize=""
<html>
<head>
<body onresize="resizeUreWithTimeout()" onload="onLoad()">
<form id="listingForm"
<table id="ListingURE" cellspacing="0" cellpadding="1" style="width: 1249px; height: 376px;">
<script type="text/javascript">
<tbody>
<tr>
<td valign="top">
<table id="ListingURE_toolbar0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<script type="text/javascript">
<td>
<script type="text/javascript">
<div id="ListingURE_toolbar0Container"
<table cellspacing="0" cellpadding="0">
<tbody>
<tr valign="middle">
<td>
<input id="**ListingURE_searchText**" class="textinputs" type="text" value=""  name="ListingURE_searchText" onselectstart="ev
4

1 回答 1

0

您使用的看起来更像 oldskool VBscript。你真的不应该使用它。

下面是一个如何使用 getElementById 和 JavaScript 来设置文本框值的示例:

<div>
    <input type="text" id="ListingURE_searchText" />
    <input type="button" onclick="fnSetValue()" title="Set value" />
</div>

<script language="javascript" type="text/javascript">
    function fnSetValue() {
        document.getElementById('ListingURE_searchText').value = 'testing 123';
    }
</script>
于 2012-12-05T20:20:48.863 回答