VBA - Error 438 trying to automate website login - vba

The program is trying to identify the login area.
The problem is that in the script of the web page there is no ID to refer to so I tried to get elements by Name but it doesn't work.
Sub test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.navigate "https://freebitcoin.io"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.document.getElementByName("email").Value = "tarnone#outlook.com"
End Sub
I have message "error 438 "object doesn't support this property or method"

There are a few elements with that class name - form-control email, thus the 0-th one is the one needed. And then with .Value the email could be set:
Sub TestMe()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://freebitcoin.io"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Dim someElement As Object
Set someElement = IE.document.getElementsByClassName("form-control email")
someElement(0).Value = "mail#some.mail"
End Sub

Related

Automate editing a field that takes value from a suggester

I tried automating a task on my CRM (using VBA on IE) where there is a field that prompts a suggester as soon as you start typing in it. Even if I enter the exact intended text, the script doesn't save the changes.
Here is the HTML code of the field to be edited:
<input class="itext" size="40" id="txtStrPoblacion" onkeyup="searchPoblacion(this.form, true);" autocomplete="off" value="Sector 14, Gurgaon, Gurgaon" type="text">
And, here is the script that I wrote:
Sub L3()
Dim IE As Object
Dim i As Long
Dim doc As HTMLDocument
Dim oHTML_Element As IHTMLElement
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
For i = 2 To 2
IE.navigate "https://in.nuptic.com/admin/admin-ModificarEmpresa.php?id_empresa=" + Cells(i, 2)
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
doc.getElementById("txtStrPoblacion").Value = Cells(i, 3)
With IE.document
Set elems = .getElementsByTagName("input")
For Each e In elems
If (e.getAttribute("value") = "Save") Then
e.Click
Exit For
End If
Next e
End With
Next
MsgBox "Done"
End Sub

Not able to login to a webpage using excel, error 424 object required

I am trying to login to this webpage, https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp
using VBA. Debugging shows me that the VBA throws an error 424 object required when username line is active (apparently it is not able to fill the username data).
Here's the code:
Sub Test()
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp")
With ie.document
.getElementById("txtUserId").Value = "ABCDE"
.getElementById("txtPassword").Value = "ABCDE"
.getElementById("submit").Click
End With
End Sub
Can anyone help me with debugging the problem while logging in to the given webpage?
Take a look at the below example:
Option Explicit
Sub Test()
Dim oIE As Object
Set oIE = CreateObject("InternetExplorer.application")
With oIE
.Visible = True
.Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp")
Do While .ReadyState < 4 Or .Busy
DoEvents
Loop
With .Document
Do While .ReadyState <> "complete"
DoEvents
Loop
With .parentWindow.frames("frmCUMain").document
.getElementsByName("txtUserId")(0).Value = "ABCDE"
.getElementsByName("txtPassword")(0).Value = "ABCDE"
.getElementsByName("cmdLogin")(0).Click
End With
End With
End With
End Sub

I am getting an error " The object invoked has disconnected from its clients" when automating my website

Below is the code i am using
Sub IE_try()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "my site"
Application.StatusBar = "Submitting"
While IE.Busy
DoEvents
Wend
delay 5
IE.Document.getElementByClass("ms-textSmall ms-srch-sb-prompt ms-helperText").Value = "abc"
IE.Documnet.getElementByName("ms-srch-sb-searchImg").Click
End Sub
Error message:
Thanks in advance :)
You are getting a strange error. In general your code is a bit wrong - you should use getElementsByClassname and not getElementsByClass. Here is something to start with, working for the StackOverflow site, writing abv in the search engine.
Option Explicit
Sub IE_try()
Dim Element As Object
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://stackoverflow.com"
While IE.Busy
DoEvents
Wend
Set Element = IE.Document.getElementsByClassname("f-input js-search-field")
Element.Item.Value = "abv"
End Sub

"Run-time automation error -2147417848 (80010108)"

I use VBA excel to parse a long list of local .htm files. The problem is that I get an error even before the programm starts to parse the HTM-files.
Error is:
VBA code:
<!-- language: lang-html -->
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub ImportHTM()
'Dim ie As InternetExplorer
Dim ie As InternetExplorerMedium
Dim html As HTMLDocument
Set ie = New InternetExplorerMedium
'Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "d:\Cloud\Dropbox\3.htm"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Loading Profile..." 'PROBLEM SEEMS TO BE HERE SOMEWHERE!
DoEvents
Loop
Set html = ie.document
Set ie = Nothing
Application.StatusBar = ""
'code code code --> which at this point isn't executed because the error occures before
Do you have any ideas what could cause the problem? Do you have any solution suggestions?
Also the command:
ie.Visible = False
doesn't seem to have any effect whatsoever since it opens the HTM-file in a new IE window.
Move the status bar update out of the loop.
Application.StatusBar = "Loading Profile..."
Do While ie.Busy Or ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Application.StatusBar = vbNullString
There is no need to rewrite the same message into the Application.StatusBar property hundreds if not thousands of times while you are waiting on a page load.
Regarding a new Internet.Explorer 'window' not inheriting the .Visible = False attribute, I recommend you switch to .Navigate2 and ShellWindows.
Addendum: Don't destroy your ie object until you are finished with the html associated with ie.document.

I can not get Web site text using VBA IE

I used the VBA below and monitored the variable IE.document. When the url is IE.navigate="http://www.mixi.jp", I could get all the web text using IE.document.all.
But in other sites like "http://www.yahoo.co.jp" , I could not get Web text. Why is that?
Sub Main()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "http://www.yahoo.co.jp"
Do While IE.Busy Or IE.readyState < 4
DoEvents
Loop
End Sub
Because this particular website's IE.document is nothing:
This seems to be the case with dynamically served sites, there are some suggestions here which I use below.
Although I am not sure you will be able to easily "get all of the text", you can certainly still iterate over the elements you're interested in extracting:
Sub Main()
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://www.yahoo.co.jp"
Do While ie.Busy Or ie.readyState < 4
DoEvents
Loop
'Create a collection of DIV elements for example
Dim myElements
DIm ele
Set myElements = ie.Document.Body.GetElementsByTagName("DIV")
'Then you can iterate over the DIV elements/etc., modify as needed.
For each ele in myElements
Debug.Print ele.InnerText
Next
End Sub