vba internet explorer click button works, but doesn`t take my inputs

Braga461

New Member
Joined
Feb 15, 2018
Messages
1
Intro> I'm new to vba for ie, I've been searching in many forums for days, but I still couldn't find someone with the same problem as me. That's why I'm creating this new thread. Would someone please help?

My goal> I want to automate my searches for flight tickets in skyscanner . com
More details> Basically I want to give in the origin, destination and dates, and click on search and collect the cheapest flight information back to my excel file.

My problem> I could successfully input origin, destination and flight dates, and I was able to click on 'search', BUT the inputs I had given (origin, destination, dates) were totally ignored by the browser, resulting in an empty search with random dates. It seems like my inputs were ignored..

My Excel looks like this>
ABCDE
1OriginDestinationDepartReturnCheapest Flight
2Hanoi (VAN)Budapest (BUD)15.06.201830.06.2018
3Cologne (CGN)Budapest (BUD)15.06.201830.06.2018

<tbody>
</tbody>



Here is my code>


Sub SearchCheapFlights()


Range("E2:F5").ClearContents

Dim ie As Object
Dim form As Object
Dim LR As Integer
Dim var1 As String
Dim var2 As String
Dim var3 As String
Dim var4 As String
Dim varResult As Object

LR = Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To LR

var1 = Cells(x, 1).Value
var2 = Cells(x, 2).Value
var3 = Cells(x, 3).Value
var4 = Cells(x, 4).Value

Set ie = CreateObject("internetexplorer.application")

ie.Visible = True

With ie
.Visible = True
.navigate "http://www.skyscanner.com"

While Not .readyState = READYSTATE_COMPLETE

Wend

End With


'Wait some to time for loading the page
While ie.Busy

DoEvents

Wend

Application.Wait (Now + TimeValue("0:00:02"))

ie.document.getElementById("js-origin-input").Value = var1
ie.document.getElementById("js-destination-input").Value = var2
ie.document.getElementById("js-depart-input").Value = var3
ie.document.getElementById("js-return-input").Value = var4

'HERE IS WHERE THE PROBLEM OCCURS
Set form = ie.document.getElementsByClassName("fss-bpk-button fss-bpk-button--large js-search-button")
Application.Wait (Now + TimeValue("0:00:02"))
form(0).Click


While ie.Busy

DoEvents

Wend

Application.Wait (Now + TimeValue("0:00:02"))

Set varResult = ie.document.getElementByClass("fqs-price")
Cells(x, 5).Value = varResult.innerText
ie.Quit

Set ie = Nothing

Next x



End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,763
Messages
6,132,583
Members
449,737
Latest member
naes

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