Hey Guys,
i'm trying to pull information from a web browser using the GetElementsByClassname method and continue to get the following error:
---------------------------
Test.ahk
---------------------------
Error: 0x80020006 - Unknown name.
Specifically: getElementsbyClassName
---> 015: Client_Name := Pwb1.document.getElementsbyClassName("PSEDITBOX")
was wondering if anyone gets this error and am i doing something incorrectly.
Using IE.Document.GetElementsByClassname
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Using IE.Document.GetElementsByClassname
You really need to post your code and more information. Specifically how Pwb1.document was created.
All I can tell you from that error message is that Pwb1.document does not possess the property getElementsbyClassName. The HTML could be telling Windows to interpret the HTML code like an older version of IE which does not support getElementsbyClassName or you could only have an old version of IE to interpret the HTML code.
FG
All I can tell you from that error message is that Pwb1.document does not possess the property getElementsbyClassName. The HTML could be telling Windows to interpret the HTML code like an older version of IE which does not support getElementsbyClassName or you could only have an old version of IE to interpret the HTML code.
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
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
Re: Using IE.Document.GetElementsByClassname
Here is some example code which might help you achieve what you want.
When it tried to refer to an element that didn't exist, there was no error message.
It would be interesting if you post your code that isn't working, or tell us what the problem was if you figure it out.
When it tried to refer to an element that didn't exist, there was no error message.
Code: Select all
q::
;link for WBGet:
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
;open this url in Internet Explorer:
;AutoHotkey Community - Index page
;https://autohotkey.com/boards/
WinGet, hWnd, ID, ahk_class IEFrame
oWB := WBGet("ahk_id " hWnd)
MsgBox % oWB.document.getElementsbyClassName("nav-link").length
MsgBox % oWB.document.getElementsbyClassName("nav-link").item[0].innerText
MsgBox % oWB.document.getElementsbyClassName("PSEDITBOX").length
MsgBox % oWB.document.getElementsbyClassName("PSEDITBOX").item[0]
MsgBox % oWB.document.getElementsbyClassName("PSEDITBOX")
oWB := ""
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Using IE.Document.GetElementsByClassname
The problem is not that the element does not exist but that the document does not support getElementsByClassName which is easy to reproduce.jeeswg wrote:When it tried to refer to an element that didn't exist, there was no error message.
Code: Select all
html =
(
<div class="example">First div element with class="example".</div>
)
document := ComObjCreate("HTMLfile")
document.open()
document.write(html)
document.close()
MsgBox % document.getElementsByClassName("example")[0].innerHTML
Now it will work.
Code: Select all
html =
(
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<div class="example">First div element with class="example".</div>
)
document := ComObjCreate("HTMLfile")
document.open()
document.write(html)
document.close()
MsgBox % document.getElementsByClassName("example")[0].innerHTML
HTML using protocols before IE9 does not support getElementsByClassName.
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
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
Re: Using IE.Document.GetElementsByClassname
Yes, I came across exactly this problem within the last few days. I guessed that that might be the problem, that HTMLfile objects couldn't support certain methods. How old are these objects, I couldn't find any good official links for HTMLfile objects when I searched, I can't even be sure of the capitalisation right now.
[EDIT:]
That reminds me, for an object, or for a GUI class like 'Edit' or 'SysListView32', is it possible to get information like a version number.
[EDIT:]
That reminds me, for an object, or for a GUI class like 'Edit' or 'SysListView32', is it possible to get information like a version number.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Using IE.Document.GetElementsByClassname
Are these DOM methods case sensitive like in JS? Not at a computer to test but was curious.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Using IE.Document.GetElementsByClassname
The method and property names like getElementsByClassName are not case sensitive. getelementsbyclassname will work fine but the element names like "example" above are case sensitive.kczx3 wrote:Are these DOM methods case sensitive like in JS? Not at a computer to test but was curious.
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
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
Re: Using IE.Document.GetElementsByClassname
Added newKey AutoHotKey.exe REG_DWORD 11001 to
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
and both scripts by FG are recognized
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
and both scripts by FG are recognized
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Using IE.Document.GetElementsByClassname
Great information to know. Much appreciated.TravisQ wrote:Added newKey AutoHotKey.exe REG_DWORD 11001 to
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
and both scripts by FG are recognized
I tried it and it works for me.
I have tried several times to get a solution by modifying the document object. The HTML code tells the document object what flavor of IE to use for interpreting it. Which means adding <meta http-equiv="X-UA-Compatible" content="IE=edge"> to the HTML code causes the document object to use a newer version of IE to interpret. But if you have no control over changing the HTML code before it is put into the document object it is much harder to tell the document object how to interpret the HTML code.
You can look at the document.compatible.0.userAgent and see the userAgent which has to do with how the HTML code is interpreted but I have been unable to add a userAgent.
I also tried creating a TextNode with http-equiv="X-UA-Compatible" content=""IE=edge" and adding the node to the HTML code but I could not get that to work either.
The RegEdit solution will work for my computer but does not solve the problem for distributing script to others but I may just have to have my script modify their Registry which I don't like messing with other computers' Registry but it might be the best way to go.
Thanks for the insight.
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
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
Re: Using IE.Document.GetElementsByClassname
You can try IE=edge as was mentioned, but also IE=9:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="X-UA-Compatible" content="IE=9">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="X-UA-Compatible" content="IE=9">
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Using IE.Document.GetElementsByClassname
All that is great but the point is, I have found no way to set the IE version after the document object is created.jeeswg wrote:You can try IE=edge as was mentioned, but also IE=9:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="X-UA-Compatible" content="IE=9">
Code: Select all
html =
(
<div class="example">First div element with class="example".</div>
)
document := ComObjCreate("HTMLfile")
document.open()
document.write(html)
document.close()
; without changing anything above, how to change the IE version of the document is the problem
;
MsgBox % document.getElementsByClassName("example")[0].innerHTML
I have found no way to interject the equivalent of "<meta http-equiv="X-UA-Compatible" content="IE=edge">" into the document after it has been fully created with HTML and have it take effect.
You could maybe pull all the HTML code from a document. Modify the HTML code as a string and then create a new document based on the modified HTML code.
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
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