Move to another tab on webpage in internet explorer using vba

K1600

Board Regular
Joined
Oct 20, 2017
Messages
181
I am trying to automate using a webpage with excel. I have managed to login to the page and select the page I need to complete some fields on however I am stuck as I can't work out how to move to another tab. On the page I need there is an area with 6 tabs in it, I want to move to a tab named "Single" but can't work out how to reference it. If I 'Inspect Element' it shows <span>Single</span>.

Can anyone advise how I need to refer to the tab to be able to select it. I'm currently using the below code which works for the rest but just not the tab:

VBA Code:
        With ie

            .AddressBar = 0
            .StatusBar = 0
            .Toolbar = 0
            .Visible = True
            .Navigate sURL1

        Do Until Not .Busy And .ReadyState = 4
        DoEvents
        Loop

'Login to site
            .Document.all("login-email").Value = WebUN
            .Document.all("login-password").Value = WebPass
            Application.Wait Now + TimeSerial(0, 0, 2)
    
        End With
    
        Do Until Not ie.Busy
        DoEvents
        Loop
    
        ie.Document.all("login-messenger").Click    'Press 'Login' button
        'ie.Document.all("nav-sendmessage").Click
        ie.Navigate sURL2            'Selects 'send' page
                    '<<<<<<<<< Single tab needs selecting here
        ie.Document.all("quicksendnumber").Value = "TEST"   
        ie.Document.all("message-body").Value = "TEST"

        Do Until Not ie.Busy
        DoEvents
        Loop

Thanks in advance.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This is the full view of the DOM Explorer if it helps.
 

Attachments

  • Picture1.png
    Picture1.png
    65.5 KB · Views: 43
Upvote 0
Search for the "Single" link, maybe like this:
VBA Code:
Dim i As Long
Dim link As Object
Set link = Nothing
i = 0
While i < ie.Document.links.length And link Is Nothing
    If ie.Document.links(i).innerText = "Single" Then Set link = ie.Document.links(i)
    i = i + 1
Wend
If Not link Is Nothing Then
    link.click
Else
    MsgBox "Single link not found"
End If
 
Upvote 0
Search for the "Single" link, maybe like this:
VBA Code:
Dim i As Long
Dim link As Object
Set link = Nothing
i = 0
While i < ie.Document.links.length And link Is Nothing
    If ie.Document.links(i).innerText = "Single" Then Set link = ie.Document.links(i)
    i = i + 1
Wend
If Not link Is Nothing Then
    link.click
Else
    MsgBox "Single link not found"
End If
Thanks. That has given me the web address that I was trying to point it to but it doesn't work for some reason. When I click on the "Single" tab it changes to the correct view below it but when I use the link it's just greyed out below it.

I've attached two screenshots showing what I get.
 

Attachments

  • Correct.png
    Correct.png
    5.6 KB · Views: 31
  • Incorrect.png
    Incorrect.png
    4.2 KB · Views: 28
Upvote 0
Does the anchor element or its parent elements have any events? If so you'll need to emulate the event with dispatchEvent or FireEvent.
 
Upvote 0
I've just stepped through it again and if it gets the link from your code then the page shows correctly, yet if I take the address and add it into the code separately, I get the greyed out sections.
 
Upvote 0
I don't think so, if I have looked in the right place that is! This is what I get.
Have you checked all the parent elements? Click the parent elements in turn along the bottom of the pane (where "span" is currently highlighted in blue).
 
Upvote 0

Forum statistics

Threads
1,223,634
Messages
6,173,476
Members
452,516
Latest member
archcalx

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