Why getElementsByClassName doesn't work for html file? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
DanielToward13
Posts: 71
Joined: 18 May 2017, 10:56

Why getElementsByClassName doesn't work for html file?

18 May 2017, 11:11

I am trying to retrieve some information from a html file but couldn't. It works fine when I use it in online webpage but fails for html files. Did I miss anything?

Code: Select all

FileRead, html, savedpage.html

document := ComObjCreate("HTMLfile")
document.write(html)

MyTitle := document.getElementsByClassName("product-name")[0].innerText

MsgBox, %MyTitle%

ExitApp
savedpage.zip
(28.72 KiB) Downloaded 20 times
User avatar
masheen
Posts: 295
Joined: 06 Dec 2016, 14:10

Re: Why getElementsByClassName doesn't work for html file?

18 May 2017, 11:35

microtorrent135 wrote:I am trying to retrieve some information from a html file but couldn't. It works fine when I use it in online webpage but fails for html files. Did I miss anything?
i think Shell.Explorer work like Web Driver. FileRead, html, not.
DanielToward13
Posts: 71
Joined: 18 May 2017, 10:56

Re: Why getElementsByClassName doesn't work for html file?

18 May 2017, 11:59

masheen wrote:
microtorrent135 wrote:I am trying to retrieve some information from a html file but couldn't. It works fine when I use it in online webpage but fails for html files. Did I miss anything?
i think Shell.Explorer work like Web Driver. FileRead, html, not.
How to do that? Could you help me by an example?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Why getElementsByClassName doesn't work for html file?  Topic is solved

19 May 2017, 07:18

I still haven't been able to find documentation for HTMLFile objects, if anyone has any good links.

This problem was also raised here:

Using IE.Document.GetElementsByClassname - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28791

Sometimes if I want to do things with HTMLFile objects, I have to use slightly older techniques. Although I could ask the user to update their HTMLFile objects (mentioned in the link I posted, if indeed that works), I would rather write a more widely compatible script.

==================================================

Based on this link:

getElementsByClassName doesn't work - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=23676

Code: Select all

;[WBGet]
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/

q:: ;check IE / HTMLFile version number
WinGet, hWnd, ID, ahk_class IEFrame
oWB := WBGet("ahk_id " hWnd)
MsgBox % oWB.document.documentMode ;11.000000
oWB := ""

oHTML := ComObjCreate("HTMLFile")
oHTML.write("")
MsgBox % oHTML.documentMode ;5.000000
oHTML := ""

oHTML := ComObjCreate("HTMLFile")
vHtml = <meta http-equiv="X-UA-Compatible" content="IE=edge">
oHTML.write(vHtml)
MsgBox % oHTML.documentMode ;11.000000
oHTML := ""
[EDIT:] Based on that link, as shown above, you could use:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
to enable getElementsByClassName.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BushMange, CEA6597, Google [Bot], VACO BenQ, w0z and 174 guests