Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

The problem is very simple: fill an inputbox on an opened IE page.

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 libraries were naturally imported (otherwise the "internetexplorer.application" wouldn't work.

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.

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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <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.

What am I doing wrong?

EDIT: When I try to execute the Sub step-by-step, I get the following:

Set Doc = ie.document

? Doc [object HTMLDocument] ( in the watchlist it is an object without any variables inside )

like image 810
Noldor130884 Avatar asked Dec 15 '14 12:12

Noldor130884


People also ask

How do you use InputBox?

Use InputBox to display a simple dialog box so that you can enter information to be used in a macro. The dialog box has an OK button and a Cancel button. If you select the OK button, InputBox returns the value entered in the dialog box. If you select the Cancel button, InputBox returns False.


1 Answers

GetElementById gets an element by its id attribute, but "Nachnamevalue" is the value of the name attribute.

To use the name:

.document.Forms("Suchform").Elements("Nachnamevalue").value = "xxx"
like image 130
Alex K. Avatar answered Oct 03 '22 03:10

Alex K.