Xeo786 wrote: ↑17 Aug 2020, 05:10
you can simply use .getElementsByClassName("someclass"), and make sure you have IE11, classname thing does not work on previous version of IE see link for support
https://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp
If U are one Windows 7 you need to upgrade it to sp1 and then u can upgrade MS.IE to IE11
Code: Select all
Elements := {}
Elements := web_browser.document.getElementsByClassName("ma-AdTag-label")
Loop % Elements.length
{
var := Elements[A_Index-1].value
MsgBox, var %A_Index% = %var%
}
Building on this is some example code to make getElementsByClassName work.
Code: Select all
;~ https://autohotkey.com/boards/viewtopic.php?p=136470#p136470
;~ Either change emulation in register or add meta content to HTML
;~ Added newKey AutoHotKey.exe REG_DWORD 11001 to
;~ HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
RegWrite, REG_DWORD, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
, AutoHotkey.exe, 11001
;~ HTML meta content
;~ <meta http-equiv="X-UA-Compatible" content="IE=edge">
html =
(
<div class="example">First div element with class="example".</div>
)
document := ComObjCreate("HTMLfile")
document.open()
document.write(html)
document.close()
MsgBox % document.documentmode
MsgBox % document.getElementsByClassName("example")[0].innerHTML
I went round and round with this problem for months when first learning DOM till I figured out that you have to make sure AHK is using newer version of IE.
There are two approaches to do this. One is edit the Registry to tell Windows to always default to IE 11 when AutoHotkey.exe uses IE. The other is to add the proper meta data at the top of the HTML content.
I tried very had to add the meta data to a DOM document by using DOM commands like createElement, SetAttribute, AppendChild, createTextNode, compatible, userAgent, etc. but never got that approach to work for adding the meta data directly to a DOM object without just getting the HTML, adding the meta text, and then creating a new DOM object from that. Never successfully figured out how to directly add meta data to an existing DOM object. Discovered the Registry thing so now it is a moot point for me on my computer but still a distributing my code problem for others to use.
If any one knows how to add this to the meta data of a DOM object, it would be useful to know. Basically how to change the
documentMode to 11.
<meta http-equiv="X-UA-Compatible" content="IE=edge">
FG