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>
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Origin[/TD]
[TD]Destination[/TD]
[TD]Depart[/TD]
[TD]Return[/TD]
[TD]Cheapest Flight[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Hanoi (VAN)[/TD]
[TD]Budapest (BUD)[/TD]
[TD]15.06.2018[/TD]
[TD]30.06.2018[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Cologne (CGN)[/TD]
[TD]Budapest (BUD)[/TD]
[TD]15.06.2018[/TD]
[TD]30.06.2018[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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