PDA

View Full Version : [SOLVED] GetElementsByClassName With IE8



rojo
02-26-2014, 04:22 AM
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...


<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

rojo
02-26-2014, 06:28 AM
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

mancubus
02-26-2014, 06:30 AM
hi. welcome to the forum. according to http://quirksmode.org/dom/core/ you can use getElementById() and getElementsByTagName() for IE8.

rojo
02-26-2014, 06:40 AM
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