VBA "Clicking" on a Button an website

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
176
Office Version
  1. 365
Platform
  1. Windows
There is a website I am trying to use VBA to input the Username and Password and then "Click" the submit button.

I was successful in placing the Username and Password into the appropriate fields, but I can't get it to "click" on the Login Button.

This is the website: https://sso.godaddy.com/login?realm=pass&app=email

Any help would be much appreciated. Thanks.<strike></strike>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I cannot get to the URL from this PC. What code are you using to enter the name/pword and try and click?

Are you using getelementbyid?

I use something like this - getElementById("btnRun").Click
 
Last edited:
Upvote 0
The code for the button I need to click is :
<button tabindex="4" class="btn btn-primary btn-block" id="submitBtn" type="submit">Sign In</button>

On other sites I used VBA to login had a name associated to it such as: <input name="cmdlogin" class="signup-submit-button" id="_login" type="submit" value="Login">

But as you can see, it just says button tabindex="4" I couldn't get it to work.



This is the code I have so far:

Dim wbname As String
Dim wsname As String
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim HTML_Element As IHTMLElement

wbname = ActiveWorkbook.Name
wsname = ActiveSheet.Name

Set objIE = New SHDocVw.InternetExplorer

With objIE
.Navigate "https://sso.godaddy.com/login?realm=pass&app=email"
.Visible = 1
Do While .ReadyState <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:02"))

'set user name and password
Set htmlDoc = .Document
Set htmlColl = htmlDoc.getElementsByTagName("INPUT")
Do While htmlDoc.ReadyState <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If htmlInput.Name = "name" Then
htmlInput.Value = Workbooks(wbname).Worksheets("Settings").Range("D2").Value
Else
If htmlInput.Name = "password" Then
htmlInput.Value = Workbooks(wbname).Worksheets("Settings").Range("D3").Value
End If
End If
Next htmlInput

'click login



Rem Set htmlDoc = .Document
Rem Set htmlColl = htmlDoc.getElementsByClassName("btn btn-primary btn-block")
Rem Do While htmlDoc.ReadyState <> "complete": DoEvents: Loop
Rem For Each htmlInput In htmlColl
Rem If htmlInput.Name = "submitBtn" Then
Rem htmlInput.Click
Rem Exit For
Rem End If
Rem Next htmlInput
End With
 
Upvote 0
Try submitting the form.
Code:
Set frm = htmlDoc.forms(0)

frm.submit
 
Upvote 0
Thanks for the help previously. I am working on logging into a different site but I can't seem to get the Username and password into their respective fields.

The url is https://dealer.carproof.com/login/.

Any help would be much appreciated..

Thanks.
 
Upvote 0
I cannot get to the URL from this PC. What code are you using to enter the name/pword and try and click?

Are you using getelementbyid?

I use something like this - getElementById("btnRun").Click
HI , pls help me with this.. i cannot able to enter the user name and password for the site below and I need to submit also...
Note : its a very simple code.. need simple code actually
my code :

Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.Navigate ("https://ctxportalvdi.emblemhealth.com/vpn/index.html")
IE.document.getElementById("dialogueStr").innerHTML = "testid"
IE.document.getElementById("response").value = "testpass"
IE.document.getElementById("SubmitButton").click
 
Upvote 0
VBA Code:
Sub test()

    With CreateObject("InternetExplorer.Application")
        Dim chng As Object, chk As Object
        .Visible = True
        .Navigate "https://ctxportalvdi.emblemhealth.com/vpn/index.html"

        While .Busy Or .readyState <> 4: Application.Wait (Now + TimeSerial(0, 0, 1)): Wend

        Set chng = .document.createEvent("HTMLEvents")
        chng.initEvent "change", True, False

        .document.GetElementById("Enter user name").Value = "user"
        .document.GetElementById("passwd").Value = "pass"

        Set chk = .document.GetElementsByname("eula_check")(0)
        chk.Checked = True
        chk.dispatchEvent chng
        .document.GetElementById("Log_On").Click

        '     .Quit
    End With

End Sub
 
Upvote 0
VBA Code:
Sub test()

    With CreateObject("InternetExplorer.Application")
        Dim chng As Object, chk As Object
        .Visible = True
        .Navigate "https://ctxportalvdi.emblemhealth.com/vpn/index.html"

        While .Busy Or .readyState <> 4: Application.Wait (Now + TimeSerial(0, 0, 1)): Wend

        Set chng = .document.createEvent("HTMLEvents")
        chng.initEvent "change", True, False

        .document.GetElementById("Enter user name").Value = "user"
        .document.GetElementById("passwd").Value = "pass"

        Set chk = .document.GetElementsByname("eula_check")(0)
        chk.Checked = True
        chk.dispatchEvent chng
        .document.GetElementById("Log_On").Click

        '     .Quit
    End With

End Sub
it is not working! throwing the below error

1606218509934.png
 
Upvote 0
it is not working! throwing the below error

View attachment 26624
The above code was written for vba. Try this for VBS, I don't know much.



VBA Code:
    With CreateObject("InternetExplorer.Application")

        .Visible = True
        .Navigate "https://ctxportalvdi.emblemhealth.com/vpn/index.html"

        While .Busy Or .readyState <> 4
             dteWait = DateAdd("s", 1, Now())
             Do Until (Now() > dteWait)
             Loop
        Wend

        Set chng = .document.createEvent("HTMLEvents")
        chng.initEvent "change", True, False

        .document.GetElementById("Enter user name").Value = "user"
        .document.GetElementById("passwd").Value = "pass"

        Set chk = .document.GetElementsByname("eula_check")(0)
        chk.Checked = True
        chk.dispatchEvent chng
        .document.GetElementById("Log_On").Click

        '     .Quit
    End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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