0

So I have some code to go to a website and then login. Then I need it to go to the password change URL. Sometimes when I run the code, I get the following error:

Runtime Error 424: Object Required

Sometimes the debugger says it is the first getelementbyid statement, but most times it says the issue is the last three getelementbyid statements. The code is below:

 Dim ie As Variant
 Dim strURL As String
 Sub login()


Set ie = New SHDocVw.InternetExplorer
 ie.Visible = True
ie.navigate "https://minecraft.net/profile"

While ie.Busy
DoEvents
Wend

ie.document.getElementById("username").Value = "ddd"
ie.document.getElementById("password").Value = "ddddddddddd"

Dim htmlForm As HTMLFormElement
Set htmlForm = ie.document.getElementById("loginForm")
 htmlForm.submit
' **********************************************************************
'IE.Document.getElementById("username").Value = "ddddd"
' IE.Document.getElementById("password").Value = "ddddd"
' IE.Document.getElementById("signin").Click
'**********************************************************************
'Pause while page loads


Application.Wait (Now + #12:00:03 AM#)
ie.navigate "https://minecraft.net/profile/password"

ie.document.getElementById("oldPassword").Value = "oldpass"
ie.document.getElementById("password").Value = "enwapss"
ie.document.getElementById("passwordConfirmation").Value = "enwapss"


Set htmlForm = ie.document.getElementById("loginForm")
htmlForm.submit

 End Sub

Thanks in advance!

1 Answer 1

1

It may be that the website isn't in a ready state, as in the site hasn't fully loaded when it's attempting to input the values.

After

ie.navigate "https://minecraft.net/profile/password"

Try adding

Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop

This will loop until the webpage has loaded similar, to the way you've done it in your above code with

Application.Wait (Now + #12:00:03 AM#)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Worked like a charm

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.