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

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

Related

VBA - Logging into Website - Login Button

Good afternoon all,
Please forgive me, I am new to VBA and have been practicing within my workbooks but for my work would be highly useful to branch out to Webscraping.
The following is my code.
Sub pullsalesdatafromonline()
Dim IE As Object
Dim doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/Login.jsp"
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
doc.getElementById("txtUserID").Click
doc.getElementById("txtUserID").Value = Usernameinserted
doc.getElementById("txtPassword").Click
doc.getElementById("txtPassword").Value = PasswordInserted
doc.getElementById("Login").Click
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/LoginSubmit.jsp"
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/ModuleSelection.jsp"
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/dashboard/main/dashboardmain.jsp"
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/rrd/matrixReport.jsp?fromPM=N"
End Sub
Here is the element that I am trying to scrape from;
<INPUT onclick=javaScript:submitForm() class=button-t type=button value=Login>
<SPAN id=Login_span class=buttonbox></SPAN>
I've looked at several other links that have looked into firing the .onclick event but, can't quite seem to figure it out.
The error in VBA highlights the:
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/ModuleSelection.jsp"
line. When my username and password enter, the page refreshes/ tries to exectute and then empties the Login and password info and leaves me on the Login page.
Would greatly appreciate someone's input.
Thank you
If you had a demo username and password to share then there was an efficient way of logging in using xhr. However, as for your current attempt concern, they are not the ids you used them within .getElementById(). Given that the following approach should log you in. Make sure to uncomment the delay, if the script fails to do the doing.
Sub pullsalesdatafromonline()
Dim IE As Object, doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.peoplestuffuk.com/WFMMCDPRD/Login.jsp"
While IE.Busy Or IE.readyState < 4: DoEvents: Wend
Application.Wait Now + TimeValue("00:00:03")
Set doc = IE.document
doc.querySelector("[name='txtUserID']").innerText = "username"
doc.querySelector("[name='txtPassword']").innerText = "password"
' Application.Wait Now + TimeValue("00:00:03")
doc.querySelector("input[value='Login']").Click
End Sub

Set doc = IE.document returns Automation Error

I'm trying to populate this form (https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood) with a set of excel data, filling each field of the form with respective column in Excel. I came across several tutorials on StackOverflow and Youtube on using VBA to open IE, navigate and fill in text box, from which I wrote these codes.
The problem comes when I run this code and Excel returns an error message box saying
Run-time Error '-2147467259 (80004005) Automation Error Unspecified Error.
I am too amateur to diagnose these codes that run perfectly on various videos on Youtube. Hope you guys can help me :)
Sub IE()
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
Dim doc As HTMLDocument
Set doc = IE.document //The error I mentioned above is in this line
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
Do While IE.Busy
DoEvents
Loop
For Each ele In IE.document.getElementsByClassName("ant-radio-input")
If ele.Value = ThisWorkbook.Sheets("Sheet1").Range("A1") Then ele.Click: Exit For
Next
doc.getElementById("phone").Value = ThisWorkbook.Sheets("Sheet1").Range("C2").Value
doc.getElementById("email").Value = ThisWorkbook.Sheets("Sheet1").Range("D2").Value
IE.Quit
End Sub
You can't set the ie.document until after you have created the IE instance and the document is loaded.
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
While IE.Busy Or IE.ReadyState <> 4:DoEvents:Wend
Set doc = IE.document

vba error message 13 IE.document

I see that someone else has asked the same question but the answer didn`t help so I am having to raise it once more,
I am running Windows 10 internet explorer 11, 64 bit
I get error mismatch error 13 at last line
I have tried Dim IE As New InternetExplorer and Dim IE As New InternetExplorerMedium but still same error ..
any idea who I can get rid of the error please ?
Thanks
Sub test()
Dim IE As Object ' InternetExplorer
Set IE = CreateObject("internetexplorer.application")
Dim html As HTMLDocument
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate "http://stackoverflow.com/"
'wait while web page load
Set html = IE.document
end sub
Try using late binding instead for the HTMLDocument. Typically you don't need to assign the document to an object, you can just interact with it without assigning it to something else.
Sub test()
Dim IE As New InternetExplorer ' Make sure you have Microsoft Internet Controls Reference added
Dim html As Object ' Or you can use HtmlDocument as the type if Microsoft HTML Object Reference is added
With IE
.Visible = True
.navigate "http://stackoverflow.com/"
While .busy Or .readystate <> 4
Application.Wait (Now() + TimeValue("00:00:01"))
DoEvents
Wend
Set html = .document
End With
End Sub

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