Object required when using GetElementByName in VBscript - authentication

Im using the following code but get object required on my getelementbyname field. Does anyone know what is going on here?
I tried so many variations:
WScript.Quit Main
Call Main
Function Main
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "myurlsamle"
WScript.Sleep 8000
With IE
.document.getElementsByName("UsernameTextBox").value = "myusername"
.document.getElementsByName("PasswordTextBox").value = "mypassword"
End With
End Function

Related

Automation Error "The object invoked has disconnected from its clients"

I'm creating vba sub in excel to automate getting data from the website. But I'm stuck with clicking an element. I kept receiving the error Run-time error -02147417848 (80010108). I don't know if I had missed something. I already tried using its id and name but it's just the same.
Sub audit()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
With ie
.Visible = True
.navigate "https://samplesite.com"
End With
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:05"))
ie.document.getElementsByClassName("xxxxxxx")(0).Click // usually the error is here
End Sub

Object Required Error on VBA (submitting IE form using VBA)

My code was working perfectly fine a few hours ago. But when I open the document now and run it, I get the error:
Run-time error '424': Object required
Here's my code:
Dim ieApp As New SHDocVw.InternetExplorer
ieApp.Visible = True
ieApp.Navigate = "<url here; sorry, its confidential>"
Do While ieApp.Busy And Not ieApp.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Dim ieElement As Object
Set ieElement = ieApp.Document.getElementById("i_specialist")
ieElement.Value = "TestValue"
The error points to:
Set ieElement = ieApp.Document.getElementById("i_specialist")
I really have no idea what went wrong. I'm thinking two possible causes:
- Object type is wrong
- Something went wrong with loading the page that the code can't find the field
Any help is appreciated! Thanks!
did you checked in the html document page that an html element with the id i_specialist is exist?
anyway when im working with htmlElements im doing it like this.. worth to give it a try...
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("i_specialist").Value = "TestValue"
End With

Error received when downloading a file from web when only submit button is present

I need to download a file from web, but only a submit button is present.
There is no url for reaching the file directly.
I tried to catch the button by its id, but VBA drops run-time error '424' (Object required).
Here is the code:
Sub keler_submit()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://www.keler.hu/T%C3%A1rsas%C3%A1gi%20esem%C3%A9nyek/"
While IE.Busy
DoEvents
Wend
Set doc = IE.document
gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")
gomb.submit
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
Thank you in advance
These lines are incorrect:
gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")
gomb.submit
doc.getElementById returns an object type so you need to use Set to assign it to a variable. The element you are trying to access should then be clicked instead of submitted. There's a high probability that IE will display a "Do you wish to open or save this file" dialog so start by making the IE object visible to show this:
IE.visible = True
Set gomb = doc.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")
gomb.click
You need a loop in there as well to ensure page has loaded. The following works:
Option Explicit
Public Sub GetInfo()
Dim IE As New InternetExplorer
With IE
.Visible = True
.navigate "https://www.keler.hu/T%C3%A1rsas%C3%A1gi%20esem%C3%A9nyek/"
While .Busy Or .readyState < 4: DoEvents: Wend
Do
Dim b As Object
On Error Resume Next
Set b = .document.getElementById("ctl00_wpm_UserControlPortlet1682286671_ctl00_wpm_UserControlPortlet1682286671_userControlPortlet_DownloadButton1")
On Error GoTo 0
Loop While b Is Nothing
b.Click
'Handle save button
'Quit '<== Remember to quit application
End With
End Sub

can't find error on my script

I have a small VBScript that opens a webpage and enters my login credentials. However, I always get an error and don't know how to fix it.
Call Main
Function Main
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://x10hosting.com/sso/login"
Wait IE
With IE.Document
.getElementByID("identifier").value = "FAKEEMAIL#my.com"
.getElementByID("password").value = "FAKEPASS"
.getElementsByName("button button-rounded button-primary")(0).Submit
End With
End Function
Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
End Sub
The error is:
line: 11
char: 9
Error: Object required: 'getElementsByName(...)(...)'
code: 800A01A8
sources: Microsoft VBScript runtime error
With IE.Document
.getElementByID("identifier").value = "FAKEEMAIL#my.com"
.getElementByID("password").value = "FAKEPASS"
.getElementsByName("button button-rounded button-primary")(0).Submit
End With
Could it because you are using the getElementsByName wrong?
getElementsByName looks for attributes with that name, but it seems you used class names.
Check this for getElementsByName
You need to use getElementsByClassName.
Check this for getElementsByClassName

VBS website login script - "Object required" error

I'm trying to write my first website login script but always getting an error in line 9 position 9 saying:
"Object Required: 'getElementByID(...)' 800A01A8.
Here's my code for the real working site:
Call Main
Function Main
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.valuedopinions.com/eng/signin"
Wait IE
With IE.Document
.getElementByID("tx_voputilities_pi1[email]").value = "my#email.com"
.getElementByID("tx_voputilities_pi1[password]").value = "mypassword"
.getElementByID("tx_voputilities_pi1[sign_in]")(0).Submit
End With
End Function
Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
End Sub
How can I write working code?
Your login form elements have the name rather than id, so you need to use getElementsByName. Also, INPUT elements don't have the Submit method, use click instead:
With IE.Document
.getElementsByName("tx_voputilities_pi1[email]")(0).value = "my#email.com"
.getElementsByName("tx_voputilities_pi1[password]")(0).value = "mypassword"
.getElementsByName("tx_voputilities_pi1[sign_in]")(0).click
End With