Using VBA to click on web page "Button"

stevecole

New Member
Joined
Mar 30, 2013
Messages
6
HI, I'm writing a Macro for Excel to go to a website, (Orbitz.com) enter departure and return dates and locations(this part works fine) then I want to be able to click on the "Get flights" Button and have it retrieve the airfare price. Then just put that price on the spreadsheet. I can put the info into the webpage no problem but I can't figure out how to make it click the "Get Flights" Button. I've done a lot of research on the web to no avail. Any assistance would be appreciated. Below is what I believe to be the pertinent webpage code as well as what I've done so far.

I think part of the problem is that I can't really identify the "Button" in the code.


Thanks Steve

My code:

Sub Test()
Dim ele As Object
Dim DeptDate As String
Dim RetnDate As String


Set objIE = CreateObject("InternetExplorer.Application")
Set ie = CreateObject("InternetExplorer.Application")

'Retreive Departure point from Excel sheet
DeptPoint = Sheets("Sheet1").Range("A1")

'Retreive Departure Date from Excel sheet
DeptDate = Sheets("Sheet1").Range("B1")

'Retreive Arrival point from Excel sheet
RetnPoint = Sheets("Sheet1").Range("A2")

'Retreive Arrival Date from Excel sheet
RetnDate = Sheets("Sheet1").Range("B2")

'Load Orbitz.com
With objIE
.Visible = True
.Navigate "http://www.orbitz.com/flights/"

'Wait till its loaded
Do While .Busy Or .ReadyState <> 4
DoEvents
Loop
'Enter Departure Point in web page
Set DeparturePoint = .document.getElementsByName("ar.rt.leaveSlice.orig.key")
DeparturePoint.Item(0).Value = DeptPoint

'Enter Arrival Point in web page
Set ArrivalPoint = .document.getElementsByName("ar.rt.leaveSlice.dest.key")
ArrivalPoint.Item(0).Value = RetnPoint


'Enter Departure date in web page
Set DepDate = .document.getElementsByName("ar.rt.leaveSlice.date")
DepDate.Item(0).Value = DeptDate

'Enter Return date in Web page
Set ReturnDate = .document.getElementsByName("ar.rt.returnSlice.date")
ReturnDate.Item(0).Value = RetnDate

'Im good down to here.**************************************

'This is where I want to put the button click code

Do While .Busy Or _
.ReadyState <> 4
DoEvents
Loop


'The rest of this needs to be customized to my needs.********************


Set objIE = Nothing

End Sub

Web page code: I think this is the area of concern. But i'm A novice at this.

<div class="group groupWithButtons">
<div class="buttons">
<div class="submit button-primary button-medium" >
<input type="submit" value="Search" name="search" data-agent="{
"type":"Interstitial"

}" data-wt-ti="SearchForm-searchButton" />
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
There's a Search Flights button, is that the one you mean?
 
Upvote 0
Steve

Add this after the code to fill in the form.
Code:
ReturnDate.Item(0).form.Item(28).Click
 
Upvote 0
One more question if you dont mind. How can I get the first price returned by the form request and put it back into my spread sheet?

Steve
 
Upvote 0
Steve

Not sure, when I tested the code I wasn't specific enough about which airport I wanted to fly to, so I was prompted to pick one instead of seeing the prices.

If you post a couple of examples of 'proper' data I'll take another look.
 
Upvote 0
On the excel sheet1
Cell A1=yvr,
Cell A2=yul

Cell B1=Departure Date in this format:MM/DD/YYYY
Cell B2=Return Date in this format:MM/DD/YYYY
 
Upvote 0

Forum statistics

Threads
1,211,772
Messages
6,103,876
Members
447,882
Latest member
LORENA

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