0
votes

I am trying to automate a webpage.

I was able to do login and click on the page. After i click in the new page i need to enter "Name" into it, but its not working getting : Microsoft VBScript runtime error '800a01a8' Object required: 'objIE.document.getElementById(..)

below is the code i am using

struser = "user"
strPass = "pswd"
 Set objIE = CreateObject("InternetExplorer.Application")
 objIE.Visible = True
objIE.Navigate "http://myurl"
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
objIE.Document.all.User.value = struser
objIE.Document.all.Password.value = strPass
objIE.Document.Forms(0).Submit()
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
objIE.Document.all.drop_mainmenu.click()
objIE.Document.all.BOX.value = "12"
objIE.Document.all.Button.Click()
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
'dim srch
'objIE.Document.getElementsByName("0_58").value = "Long"
'srch.value = "Long"
 set el = objIE.document.getElementById("C0_58") 
'If el.value is nothing Then
 set el.value = "Long"
'End If
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.SendKeys "^%L"

below is the snippet of source code for that field.

enter code here<input name="0_58" tabindex="6" title="Alpha Name" class="textfield" id="C0_58" style="width: 218px; 
vertical-align: top; cursor: auto;" onmouseover="updateHelpCursor('',this)" onhelp="hp('0_58')" 
onfocus="FCHandler.onFocus(this,'',false)" onblur="FCHandler.onExit(this,false,'',false)" 
type="text" maxlength="40" value=" " htmlpostflag="false">

enter code here
1
Does this work ?? set el = objIE.document.getElementById("C0_58")..... Enclose the ID in Double Quotes - Mithilesh Indurkar
same error with set el = objIE.document.getElementById("C0_58") - Kalpanaraim
forgot to update, this field is inside an iframe which got multiple tables and spans inside it. - Kalpanaraim
Then there might be a problem with the objIE object. Do you get an error with 'objIE .Visible = True' statement. Try putting it before set el = objIE.document.getElementById(C0_58)... If this also throws error, your IE object is not set correctly or not passed to this object correctly. Can you please post the code from where this objIE coming. - Mithilesh Indurkar
struser = "user" strPass = "pswd" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate "myurl" While objIE.Busy = True WScript.Sleep 100 Wend While objIE.ReadyState <> 4 WScript.Sleep 100 Wend - Kalpanaraim

1 Answers

0
votes

Surprising, I have tried the below code and it works perfectly when saved and executed from a vbs file.

 Set objIE = CreateObject("InternetExplorer.Application")
 objIE.Visible = True
 objIE.Navigate "https://www.google.co.in/"
 Wscript.Sleep(5000)

 Set objEL = objIE.Document.GetElementById("lst-ib")
 objEL.Value = "Mithilesh"
 MsgBox objEL.Value 'Displays Mithilesh

Also, the below might not be useful in resolving the error you are getting but look at the way I am setting the value in the field. You should not use

set el.value = "Long"

Instead use

el.value = "Long"

Try this

ObjIE.Document.Frames("Iframe").contentwindow.document.getElementsById("C0_58")

Or:

For Each frame In iframes
    Set inputs = frame.contentwindow.document.getElementsByTagName("input")
    For Each obj In inputs
        If obj.className = "C0_58" Then
            'MsgBox "found "C0_58" in frame:" & i
        End If
    Next
i = i + 1
Next

The best I could suggest is to play around the frames and their child elements. If possible, you could post your HTML, we could have a look at that