can't find error on my script - authentication

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

Related

Object required when using GetElementByName in VBscript

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

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

Need to use VBA to select an option from a drop down list in Internet Explorer

I have successfully got my code to open IE, navigate to the webpage I need, and login. I now need to select an option from a drop down list - please see the following html code:
html code for the list
How do I select the "TPS Managed Conservative - Dec 11" option from the dropdown.
My code so far:
Sub Strategic_Alpha_Monthly_Pivots_1_MASTER()
' open IE, navigate to the desired page and loop until fully loaded
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
my_url = "http://analytics.financialexpress.net/login.aspx"
With ie
.Visible = True
.navigate my_url
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
End With
' Input the userid and password
ie.document.getElementById("txtPassword").Value = "xxxxx"
' Click the "Search" button
ie.document.getElementById("btnAction").Click
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.document.getElementById("ListPortfolio").Select
End Sub
selectedIndex or Value could be used. According to the screenshot the value 983678630 can be used. HTH
If Not VBA.IsNull(ie.document.getElementById("ListPortfolio")) Then
Dim htmlSelect
Set htmlSelect = ie.document.getElementById("ListPortfolio")
' htmlSelect.selectedIndex = 6
htmlSelect.Value = 983678630
Else
MsgBox "Element 'ListPortfolio' was not found", vbExclamation
End If

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

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