click in an html form text box to send key strokes

Shodi

Board Regular
Joined
May 24, 2016
Messages
53
Hello everyone hope all of you have been staying safe
I am trying to automate with Excel VBA an online form filling procedure where we first need to login before updating the online form
To login we have 4 steps
the first is to key in the username
The second is to key in the password
The third is to key in the captcha
And the fourth is to click the login button
Since the captcha is involved I am doing this on a browser that is already open - so that I can key in the captcha into an excel cell and read from there - so I have written the code to access an already open internet explorer using the shell command. And have reached the stage where the first three steps are completed.
But I am not able to click on the login button because the login button is not active.
After a few trials I found that the login button only gets activated if there are 5 characters in the captcha textbox and entered via a keystroke.. at least the last character needs to be entered via a keystroke
So what I am essentially looking for is way to have VBA replicate a mouse click in the textbox so that we have an active html textbox with the cursor blinking in it
Can we do this, please help me.

Am providing the code I have here.

VBA Code:
Sub Access_Page()

Dim shellWins As SHDocVw.ShellWindows
Dim IE As New SHDocVw.InternetExplorer
Dim HtmlDoc As MSHTML.IHTMLDocument
Dim ID_box As MSHTML.IHTMLElement, pWrd As MSHTML.IHTMLElement
Dim iCaptcha As MSHTML.HTMLInputElement, iLoginBtn As MSHTML.HTMLInputElement
Dim I_Path As String

Set shellWins = New SHDocVw.ShellWindows
For Each IE In shellWins
    If IE.Name = "Internet Explorer" And IE.LocationURL = "website url" Then
        Set HtmlDoc = IE.document
        Exit For
    End If
Next IE

Set ID_box = HtmlDoc.getElementById("txtUsername")
Set pWrd = HtmlDoc.getElementById("txtPassword")
Set iCaptcha = HtmlDoc.getElementById("txtCaptcha")
Set iLoginBtn = HtmlDoc.getElementById("btnSubmit")

ID_box.Value = Range("B2").Value
pWrd.Value = Range("C2").Value
iCaptcha.Value = Range("D2").Value
iLoginBtn.Click

Do while IE.ReadyState <> READYSTATECOMPLETE
DoEvents
Loop

End Sub

I did a bit of research and learned about SendKeys and using ExcelAPIs but I'm just taking baby steps here and not sure how these work or how to implement these ?.



Looking forward to all the help I can get. Thanks in advance. :)
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello everyone hope all of you have been staying safe
I am trying to automate with Excel VBA an online form filling procedure where we first need to login before updating the online form
To login we have 4 steps
the first is to key in the username
The second is to key in the password
The third is to key in the captcha
And the fourth is to click the login button
Since the captcha is involved I am doing this on a browser that is already open - so that I can key in the captcha into an excel cell and read from there - so I have written the code to access an already open internet explorer using the shell command. And have reached the stage where the first three steps are completed.
But I am not able to click on the login button because the login button is not active.
After a few trials I found that the login button only gets activated if there are 5 characters in the captcha textbox and entered via a keystroke.. at least the last character needs to be entered via a keystroke
So what I am essentially looking for is way to have VBA replicate a mouse click in the textbox so that we have an active html textbox with the cursor blinking in it
Can we do this, please help me.

Am providing the code I have here.

VBA Code:
Sub Access_Page()

Dim shellWins As SHDocVw.ShellWindows
Dim IE As New SHDocVw.InternetExplorer
Dim HtmlDoc As MSHTML.IHTMLDocument
Dim ID_box As MSHTML.IHTMLElement, pWrd As MSHTML.IHTMLElement
Dim iCaptcha As MSHTML.HTMLInputElement, iLoginBtn As MSHTML.HTMLInputElement
Dim I_Path As String

Set shellWins = New SHDocVw.ShellWindows
For Each IE In shellWins
    If IE.Name = "Internet Explorer" And IE.LocationURL = "website url" Then
        Set HtmlDoc = IE.document
        Exit For
    End If
Next IE

Set ID_box = HtmlDoc.getElementById("txtUsername")
Set pWrd = HtmlDoc.getElementById("txtPassword")
Set iCaptcha = HtmlDoc.getElementById("txtCaptcha")
Set iLoginBtn = HtmlDoc.getElementById("btnSubmit")

ID_box.Value = Range("B2").Value
pWrd.Value = Range("C2").Value
iCaptcha.Value = Range("D2").Value
iLoginBtn.Click

Do while IE.ReadyState <> READYSTATECOMPLETE
DoEvents
Loop

End Sub

I did a bit of research and learned about SendKeys and using ExcelAPIs but I'm just taking baby steps here and not sure how these work or how to implement these ?.



Looking forward to all the help I can get. Thanks in advance. :)
Hi all was hoping to get some assistance on this... please.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top