IE COM. Page does not support ClassName?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

IE COM. Page does not support ClassName?

18 Jun 2018, 09:03

Hi, can it be that webpage does not supports (does not allows?) to work with Class? getElementById works fine, getElementsByTagName works fine, but getElementsByClassName does not respond at all even via F12. I have tried to get visual events, but it looks like the page does not allows to create event too. It gives me an error on that line. It's very hard to automate the page without using ClassName, because Id is not in the all fields and TagName is very unstable.
any ideas why ClassName doesn't work?

lets say HTML code is:

Code: Select all

<DIV class="sppContent editmode"><H2>MY TEXT HERE</H2>
<DIV class=message id=statusMessage style="BORDER-TOP: 0px; BORDER-RIGHT: 0px; BACKGROUND: #4da14d; BORDER-BOTTOM: 0px; COLOR: white; PADDING-BOTTOM: 3px; PADDING-TOP: 3px; PADDING-LEFT: 3px; BORDER-LEFT: 0px; DISPLAY: none; PADDING-RIGHT: 3px"></DIV>
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: IE COM. Page does not support ClassName?

18 Jun 2018, 09:23

could be simply the missing quotes
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IE COM. Page does not support ClassName?

18 Jun 2018, 12:11

icuurd12b42 wrote:could be simply the missing quotes
no :) it's not a silly mistake in the path. The page does not respond to ClassName and give the message that object cannot connect to that type of element (ClassName). And the same applys on all ClassNames in the page.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: IE COM. Page does not support ClassName?

18 Jun 2018, 14:59

euras wrote:Hi, can it be that webpage does not supports (does not allows?) to work with Class? getElementById works fine, getElementsByTagName works fine, but getElementsByClassName does not respond at all even via F12. I have tried to get visual events, but it looks like the page does not allows to create event too. It gives me an error on that line.
The HTML meta data can define what version of IE should be used to process the HTML. If it specifically says this HTML was designed for IE 6 and only use IE 6 to process it then it can be difficult to ignore what the HTML says and process it differently.

If on the other hand the HTML does not say one way or another and your software is deciding then that can be fixed with a registry entry. The registry contains a list of what version each piece of software would like to use if the HTML itself does not define what version to use.

Code: Select all

;~ 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
This will create a registry entry under Internet Explorer telling it to use the newest version avaialbe when AutoHotkey.exe uses IE. This only needs to be run once and from then on IE knows what version AutoHotkey.exe likes using as the default.

This can be pretty important because if IE is not told it defaults to the oldest version available which only allows the most basic of commands.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IE COM. Page does not support ClassName?

19 Jun 2018, 02:09

FanaticGuru wrote: FG
the page have this line:

Code: Select all

<META http-equiv=X-UA-Compatible content=IE=8;>
while my IE is 11. Can it be the problem? I have tried to use your method but either it doesn't work for me or I used it wrong.. I still get the error message that getElementsByClassName does not exist.

Code: Select all

RegWrite, REG_DWORD, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
, AutoHotkey.exe, 11001
pwb := WBGet()
MsgBox % pwb.document.getElementsByClassName("message")[0].innerText ;Get classname and Array value
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: IE COM. Page does not support ClassName?

19 Jun 2018, 03:53

document.querySelector
Look at the examples in link below:
https://www.w3schools.com/jsref/met_doc ... lector.asp

HTH
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: IE COM. Page does not support ClassName?

19 Jun 2018, 08:34

euras wrote: the page have this line:

Code: Select all

<META http-equiv=X-UA-Compatible content=IE=8;>
while my IE is 11. Can it be the problem?
I think so. GetElementsbyClassName seems to need at least IE 9 (compare, for example, https://developer.mozilla.org/de/docs/W ... yClassName). And as far as I understand FG, this is the case where you cannot do anything. The content mode to use is explicitly stated in the original html. Then, even the addition of the registry key won't help...
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: IE COM. Page does not support ClassName?

19 Jun 2018, 12:02

gregster wrote:
euras wrote: the page have this line:

Code: Select all

<META http-equiv=X-UA-Compatible content=IE=8;>
while my IE is 11. Can it be the problem?
I think so. GetElementsbyClassName seems to need at least IE 9 (compare, for example, https://developer.mozilla.org/de/docs/W ... yClassName). And as far as I understand FG, this is the case where you cannot do anything. The content mode to use is explicitly stated in the original html. Then, even the addition of the registry key won't help...
Yea, if the HTML from the website is specifically saying process the HTML code using IE 8 then it is hard to override that specific direction.

The website HTML is basically saying we only designed this HTML for IE 8 and we know it will work on IE 8 so only use IE 8 or anything else could cause problems.

All versions of IE have backward compatibility so even though you have IE 11 installed it runs in an emulation mode and runs using IE 8 rules, including methods and properties.

I have discovered no way to change the documentMode of a document once it has already processed the HTML code and created the document object from that HTML code.

Now on the plus side it is pretty easy to create a function that does the same thing as GetElementsbyClassName.

Code: Select all

GetNodesByClassName(ByRef Doc, Names*)
{
	Nodes := {}
	for index, Name in Names
		Needle .= Name "|"
	Needle := "i)\b" SubStr(Needle,1,-1) "\b"
	list := Doc.getElementsByTagName("*")
	Count := list.length
	loop %Count%
		if (child := list[A_Index-1])
			if (child.className ~= Needle)
				Nodes.Push(child)
	return Nodes
}
Then you can do stuff like this:

Code: Select all

GetNodesByClassName(oDocument,"customer")[1].outerHTML
This will get from oDocument all the nodes named "customer" then it will return the outerHTML of the first node. Elements and Nodes are pretty much the same thing.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer, gongnl and 274 guests