excelvbaweb-scraping

VBA: Click on Tab from Web page (getelementby?)


I need to click on the import tab from a web page, I have tried things like:

ieApp.document.getElementsByTagName("#tab-import")(1).Click
ieApp.document.getElementsByName("#tab-import").Click
ieApp.document.getElementsById("#tab-import").Click
ieApp.document.all.Item("#tab-import")(1).click
ieApp.document.all.Item("Import").Click

The last one runs correctly but nothings happen; this is the linecode that shows the inspect element tool:

<li><a href="#tab-import" data-toggle="tab">Import</a></li>

Also I have tried to open the web page with the url of the href="#tab-import" but the page starts on the first tab (export)

I don't know what to do, please help.


Solution

  • I'm giving this solution considering the fact that href="#tab-import" appear once in that page you are dealing with and the version of IE is later than 9. The portion of html is too minimum to guess a unique selector.

    Dim Html As HTMLDocument
    
    Set Html = ieApp.document
    Html.querySelector("a[href='#tab-import']").Click
    

    Reference to add to the library:

    Microsoft HTML Object Library