How to navigate through multiple links on website

2019-03-06 23:51发布

问题:

I want to select options on multiple pages using vba internet explorer and i am able to open multiple tabs and multiple links using vba but only able to navigate on first page. Please check the coding given below for your reference:-

Sub mmtlink2()

Dim IE As New SHDocVw.InternetExplorer
Dim st As String
Dim htmldoc As MSHTML.HTMLDocument


Dim i As Long, d As Long, b As Long

'Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

d = 2

For i = 1 To d

If i = 1 Then
    IE.navigate "https://www.makemytrip.com/air/search?tripType=O&itinerary=BOM-DXB-D-02Dec2017&paxType=A-1&cabinClass=E"

Else
    IE.Navigate2 "https://www.makemytrip.com/air/search?tripType=O&itinerary=BOM-DXB-D-03Dec2017&paxType=A-1&cabinClass=E", 2048
End If

 Do While IE.Busy = True Or IE.readyState <> 4
 Loop

    Set htmldoc = IE.document

    htmldoc.getElementById("Non stop").Click
Next i

End Sub

Please provide any solution to navigate on second page as well.

回答1:

Correct your syntax within the Else Statement:

Else
    IE.Navigate url, 2048

instead of

Else
    IE.Navigate2 url, 2048