We help IT Professionals succeed at work.

Excel VBA form fill IE

RAJESH JOSHI
RAJESH JOSHI used Ask the Experts™
on
I am trying the following code.
Sub redfin_test()
'Application.ScreenUpdating = False

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


IE.Navigate "https://www.redfin.com"
Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("00:00:1"))

IE.Document.getElementsByClassName("search-input-box")(0).Value = "5606 Trout Creek Pass Dr,CO,80917"
Application.Wait (Now + TimeValue("00:00:4"))
IE.Document.Forms(0).Submit
 Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
 Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
 Application.Wait (Now + TimeValue("00:00:4"))
 'IE.Quit
 'Set IE = Nothing


'Application.ScreenUpdating = True
End Sub

Open in new window


It does not show search result.
Manually I enter same value, it returns the result.
Where is my mistake?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
See if this works for you...
Sub redfin_test()
'Application.ScreenUpdating = False
Dim ie As Object
Dim str As String
Dim i As Long

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

ie.Navigate "https://www.redfin.com"
Do While ie.Busy = True Or ie.ReadyState <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("00:00:1"))

ie.document.getelementsbyclassname("search-input-box")(0).Focus

str = "5606 Trout Creek Pass Dr,CO,80917"

For i = 1 To Len(str)
    SendKeys Mid(str, i, 1)
Next i

Application.Wait (Now + TimeValue("00:00:4"))
ie.document.getelementsbyclassname("item-title block")(0).Click

'IE.Quit
'Set IE = Nothing

End Sub

Open in new window

Author

Commented:
Dear SubodhJi,

Thank you, but
I tried. Actually class name for the button is "inline-block SearchButton clickable float-right"
So I tried ie.Document.getElementsByClassName("inline-block SearchButton clickable float-right")(0).Click
But SendKeys does not work. Every time it takes same values even if I change the str value.
e,g, str = "3953 Iron Horse Trl,CO,80917"

You may please test at your end please.

With regards,
Rajesh.
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
I tested it and it worked on my end. Please refer to the demo video.
IENavigation.mp4

Author

Commented:
Will you please change the search str once to
str = "3953 Iron Horse Trl,CO,80917" and check?

Whatever you search manually remains in the textbox
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
It worked for me, refer to the video.
IENavigation2.mp4