Consulting

Results 1 to 4 of 4

Thread: GetElementsByClassName With IE8

  1. #1
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    3
    Location

    GetElementsByClassName With IE8

    Hi All,

    First time to the forum and the first post ever I think! Trying to learn VBA, HTML and hopefully databases but so far very much a beginner.

    I'm hoping someone can help me with this, normally I would search the web for a solution but this one is hard for me!

    I have a VBA program that pulls a table form a website and pastes this on a sheet, I have it working fine on my home pc but cant get it to work on my work PC. I'm pretty sure its down to Internet Explorer as I am using IE11 and work is IE8.

    Once logged into the website I pull a table using its classname, there is no ID or Tag name, I understand IE8 doesn't support GetElementsByClassName so have tried using querySelector but the website isn't using CSS3 so that doesn't work either.

    The nesrest I have got it by using getElementById but this gets the form element and then I don't know how to get the div element from the form element..?

    I really hope this makes sence as I am not 100% sure what I am talking about.

    Working code for IE9+
    'get the table based on the table’s class
         Set ieDoc = ieApp.document
    
         Set ieTable = ieDoc.GetElementsByClassName("log")(0)
    
    'copy the tables html to the clipboard and paste to the sheet
    
         If Not ieTable Is Nothing Then
        Set clip = New DataObject
        clip.SetText "<html>" & ieTable.outerHTML & "</html>"
            clip.PutInClipboard

    and I can use this to get the HTMLFormElement

    Set ietable = ieDoc.getElementById("aspnetForm")
    start of the table...

    HTML Code:
     <div class="log" reportentryid="11719" entrytype="Log">
     <table class="grid scrollable">

    Be grateful if someone can help, please let me know if I need to explain or post more...?

    Cheers

  2. #2
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    3
    Location
    So I found a solution, its not pretty but it works, and as the website wont be changing should do the job. I used the getElementById and navigated my way down, annoyingly not much had an ID so hand to navigate down a few times...

    Set ieTable = ieDoc.getElementById("aspnetForm").Children(17).Children(0).Children(1).Children(0).Children(1).Children(0).Children(2).Children(1)
    I will close this but if anyone has any tips for next time that would be great!

    Cheers

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi. welcome to the forum. according to http://quirksmode.org/dom/core/ you can use getElementById() and getElementsByTagName() for IE8.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    3
    Location
    Edit:

    The parent had an ID, so looks like this now, much better...

    Set ieTable = ieDoc.getElementById("content").Children(1)
    Sorry for all the posts, maybe it will help someone one day! Cheers

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •