Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 11:33
In the javascript below in an Internet Explorer page I'm trying to obtain the value of iw_board_deviceName.
Code: Select all
<html>
<head>...</head>
<frameset rows="57,1*">
<frame name="toplogo" src="top.asp" frameborder="0" noresize="" scrolling="NO">...</frame>
<frameset cols="230,*">
<frame name="contents" src="contents.asp" frameborder="0">...</frame>
<frame name="main" src="setup_option.asp" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto">
<html>
<head>...</head>
<body onload="iw.ChangeOnLoad();">
<h2>System Information</h2>
<form name="sysinfo" onsubmit="return CheckValue(this)" action="/forms/iw_webSetParameters" method="POST">
<table width="100%">
<tbody>
<tr>
<td width="30%" class="column_title">Device name</td>
<td width="70%">
<input name="iw_board_deviceName" type="text" size="40" maxlength="31" value="Device MAC Address" />
I've referred to several pages online to retrieve this value, however I have been unsuccessful. Here are a few I've been referencing.
https stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript Broken Link for safety
https codippa.com/how-to-select-an-element-inside-a-frame-using-javascript/ Broken Link for safety
Code: Select all
;Create ie Window
wb := ComObjCreate("InternetExplorer.Application")
;Make ie Window Visible
wb.Visible := 1
;Navigate to Moxa page
wb.Navigate("http 192.168.127.253 ") Broken Link for safety
;Wait while page loads
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy
Sleep, 20
;Retrieve MAC address - TESTING
MAC := wb.window.frame["main"].document.getElementsByName("iw_board_deviceName")
;MAC := wb.window.frames["main"].document.getElementID("iw_board_deviceName")
;MAC := wb.document.getElementById("myframe1").contentWindow.document.getElementByID("iw_board_deviceName")
;Display Info from the page
MsgBox %MAC%
Can anyone help figure out what I'm doing wrong? The msgbox currently displays no information, so I'm obviously failing to retrieve the info I'm looking for.
Edit: The wb.Navigate line of code I have works. For some reason it keeps stripping the :// between the IP address and http on this forum.
Last edited by
ilhom on 06 Sep 2019, 15:51, edited 3 times in total.
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 12:43
In this part wb.window.frame["main"], it says frame without a final s.
Is that a typo just here in your post? or is it also a typo in your code?
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 12:47
Getfree wrote: ↑06 Sep 2019, 12:43
In this part
wb.window.frame["main"], it says
frame without a final
s.
Is that a typo just here in your post? or is it also a typo in your code?
I tried with both the
s and without the
s just to test. No luck with either one.
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 13:00
You should use frames.
Also, getElementsByName returns a collection, so you need to get its first element with square brakets and then its value
For example getElementsByName('name')[0].value
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 14:41
MAC := wb.window.frames["main"].document.getElementsByName("iw_board_deviceName")[0].value
I get an error on this line stating it's an unknown name.
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 15:23
What happens if instead of wb.window.frames you write wb.document.frames ?
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 15:37
I received an unspecified error doing that.
I searched through the source code of the site and that is the only instance of iw_board_deviceName so I don't see how that name would be getting confused.
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 15:47
What kind of control is wb? Is it a Shell.Explorer ActiveX control? How are you creating it?
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 15:52
Getfree wrote: ↑06 Sep 2019, 15:47
What kind of control is
wb? Is it a Shell.Explorer ActiveX control? How are you creating it?
Edited original post. Can't believe I forgot to include the variable creation.
wb := ComObjCreate("InternetExplorer.Application")
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 15:59
Do any of these give you the number 3?
MsgBox % wb.document.frames.length
MsgBox % wb.document.parentWindow.frames.length
MsgBox % wb.window.frames.length
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 16:05
Message box displayed 3:
MsgBox % wb.document.frames.length
MsgBox % wb.document.parentWindow.frames.length
Unknown name error, and displayed nothing in the message box:
MsgBox % wb.window.frames.length
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 06 Sep 2019, 16:12
You are all set, then.
MAC := wb.document.frames["main"].document.getElementsByName("iw_board_deviceName")[0].value
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 06 Sep 2019, 16:35
That line of code provides me this error
Error: 0x80020101 -
Specifically: Frames
-
Getfree
- Posts: 231
- Joined: 12 Oct 2014, 18:00
Post
by Getfree » 07 Sep 2019, 19:36
Try your script on a local HTML file, like this one:
Code: Select all
<html>
<frameset rows="57,1*">
<frame name="toplogo" src="about:blank"></frame>
<frameset cols="230,*">
<frame name="contents" src="about:blank"></frame>
<frame name="main" src="frame.html">
</frameset>
</frameset>
</html>
Create a
frame.html file as well.
This is to rule out that the problem isn't some sort of permissions or access violations related to cross-frame scripting.
-
grimboto
- Posts: 53
- Joined: 09 Jul 2014, 19:20
Post
by grimboto » 08 Sep 2019, 01:20
try adding parentWindow
Code: Select all
wb.document.parentWindow.frames["main"].document.getElementsByName("iw_board_deviceName")[0].value
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 09 Sep 2019, 09:19
Getfree wrote: ↑07 Sep 2019, 19:36
Try your script on a local HTML file, like this one:
Code: Select all
<html>
<frameset rows="57,1*">
<frame name="toplogo" src="about:blank"></frame>
<frameset cols="230,*">
<frame name="contents" src="about:blank"></frame>
<frame name="main" src="frame.html">
</frameset>
</frameset>
</html>
Create a
frame.html file as well.
This is to rule out that the problem isn't some sort of permissions or access violations related to cross-frame scripting.
I tried navigating to this html file and I still receive the same error:
Error: 0x80020101 -
Specifically: Frames
grimboto wrote: ↑08 Sep 2019, 01:20
try adding parentWindow
Code: Select all
wb.document.parentWindow.frames["main"].document.getElementsByName("iw_board_deviceName")[0].value
I still received the aforementioned frame error.
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 11 Sep 2019, 09:26
Bumping.
Still struggling on this and I feel a bit stumped. I've searched online for a while now and everything I've found is consistent with what was suggested here. Perhaps it has something to do with the fact the frame is within 2 framesets?
-
malcev
- Posts: 1769
- Joined: 12 Aug 2014, 12:37
Post
by malcev » 11 Sep 2019, 09:56
Code: Select all
Pwb:= ComObjCreate( "InternetExplorer.Application" )
Pwb.Navigate("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
Pwb.Visible:= True
While ( Pwb.Busy || Pwb.ReadyState != 4 )
Sleep 10
msgbox page loaded
oIE := IEGet()
msgbox % oIE.document.documentElement.OuterHtml
iFrame := ComObject( 9, ComObjQuery(oIE.document.parentWindow.frames["iframeResult"],"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
msgbox % iFrame[0].document.documentElement.OuterHtml
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
-
ilhom
- Posts: 52
- Joined: 19 Aug 2019, 17:58
Post
by ilhom » 11 Sep 2019, 11:46
malcev wrote: ↑11 Sep 2019, 09:56
Code: Select all
Pwb:= ComObjCreate( "InternetExplorer.Application" )
Pwb.Navigate("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
Pwb.Visible:= True
While ( Pwb.Busy || Pwb.ReadyState != 4 )
Sleep 10
msgbox page loaded
oIE := IEGet()
msgbox % oIE.document.documentElement.OuterHtml
iFrame := ComObject( 9, ComObjQuery(oIE.document.parentWindow.frames["iframeResult"],"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
msgbox % iFrame[0].document.documentElement.OuterHtml
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
I adjusted the
msgbox % oIE.document.documentElement.OuterHtml to
FileAppend, % oIE.document.documentElement.OuterHtml, GuiFrameTest.txt so that I could inspect the output easier. I'm not that familiar with JavaScript, so I can't tell what exactly I'm looking for. Could an explanation be provided for the
IEGet() function, and what exactly iFrame is looking for?
-
malcev
- Posts: 1769
- Joined: 12 Aug 2014, 12:37
Post
by malcev » 11 Sep 2019, 12:43
You can search for commands that are used in that function and read manual what they do.