0
Sub login()

Dim objie As InternetExplorer

    Set objie = New InternetExplorer

    objie.Visible = True

    objie.navigate "https://kite.zerodha.com/"

    Do While objie.Busy = True Or objie.readyState <> 4: DoEvents: Loop
    objie.document.getElementsByTagName("input")(0).Value = "abcdefgh"

    objie.document.getElementsByTagName("input")(1).Value = "abcdefgh"
    objie.document.getElementsByTagName("button")(0).Click


End Sub

The website I am trying to automate is not accepting text sent from vba. So I tried sendkeys method and it worked. But I want to run the Internet explorer in background. Is there any way to do this.

2
  • That's odd. I can step through with F8 and all three login actions work for me. Commented Sep 22, 2018 at 13:47
  • User Id and password is displayed on webpage page. But after pressing login button, I am getting the error "user id should be minimum of six characters" which is not the case when I manually type with keyboard. Commented Sep 22, 2018 at 18:22

1 Answer 1

1

I would use selenium basic in this case. It is far more reliable. After install, VBE > Tools > References, add reference to selenium type library.

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://kite.zerodha.com/"
    With d
        .AddArgument "--headless"
        .Start "Chrome"
        .get URL
        .FindElementByCss("[type=text]").SendKeys "abcdef"
        .FindElementByCss("[type=password]").SendKeys "123456"
        .FindElementByCss("[type=submit]").Click
        Stop '<== Delete me later
        '.Quit '<==Uncomment me later
    End With
End Sub

With IE you can add .Focus and use .innerText as follows:

Option Explicit
Sub login()
    Dim objie As InternetExplorer
    Set objie = New InternetExplorer
    objie.Visible = False
    objie.navigate "https://kite.zerodha.com/"

    Do While objie.Busy = True Or objie.readyState <> 4: DoEvents: Loop

    With objie.document
        .querySelector("[type=text]").Focus
        .querySelector("[type=text]").innerText = "abcdef"
        .querySelector("[type=password]").Focus
        .querySelector("[type=password]").innerText = "123456"
        .querySelector("[type=submit]").Click
    End With
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.