Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GetElementByID from a classic Active Server Page (ASP)


  • Please log in to reply
10 replies to this topic
jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

Dear Forum,

 

Trying to find a way to return value from the IE9 DOM when a Classic ASP page is loaded using something like:

 

result := ieDOMObject.document.getElementById('<%=FirstName.ClientID %>').value

 

No idea yet if the code will work because first issue is that SciTE4AutoHotkey/AHK_L reports

 

==> The leftmost character above is illegal in an expression.
Specifically: '
 

How can one use the single quote " ' ", HEX 27, (on the key below the double quote) in the code ?

 

I've tried escaping it with the " ` " (on the key below the tilde) and " \\ " but no luck getting the script to run.

 

Thanks



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

Hey jablonsky

 

I'm not sure i can really help answer this but i'll say something. smile.png

 

To me that ID name does not look like any i have seen before not saying it can't look like that it just does not look rigth to me

 

normally the iWB2 Learner (iWebBrowser2) http://tinyurl.com/9lnfxps helps me with finding a DOM elements name or ID

 

And some "normal" AHk v1.1 COM code will look something like this:

wb := ComObjCreate("InternetExplorer.Application") ; create a IE instance
wb.Visible := True
wb.Navigate("Google.com")
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
wb.Document.GetElementById("gbqfq").Value := "site:autohotkey.com Active Server Page (ASP)"
Edit_Value := wb.Document.GetElementById("gbqfq").value
Msgbox % Edit_Value
return

 

The " is used in AHk COM syntex not the ' like in javascript or at least not that i know of but i can be wrong.
 
Hope it helps

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

Blackholyman,

 

Good points all. My limited understanding is that ASP has two element IDs, the one we are familiar with from a standard HTML DOM and then a "ClientID" that is generated on the fly. That is the reason for the curious syntax which is based, as you note, on javascript examples I found on the web. I was thinking I could start trying different permutations but immediately ran into the issue with single quotes.

 

As for iWB2 Learner.exe I have indeed used it. What I am really interested in however is finding a copy of iWB2 Leaner.ahk that will run so I can better understand how the HTML DOM works. Have you come across a working copy of the code for iWB2 Learner.ahk ? While on that topic; do you know whether iWB2 Learner.ahk is meant to run under AHK_L ?

 

By the way, kudos on your most excellent youtube login video and thank you also for responding here.

 

Yes, it helps icon_smile.gif



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
... What I am really interested in however is finding a copy of iWB2 Leaner.ahk that will run so I can better understand how the HTML DOM works.

 

I'm not sure studying that script is the best route for learning the HTML DOM - especially since I am quite lazy about commenting my code. But anyways, try this out, see if I messed up updating it:

 

iWB2 Learner.ahk - depends on Anchor.ahk & Acc.ahk



jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

Jethrow,

 

Truly a gift from the gods icon_smile.gif

 

Thank you, it runs perfectly. For my fellow earthlings; be sure to bring the Anchor.ahk and Acc.ahk (tiny blue links visible to the right) down as well. I just put them in the same directory and added these two lines immediately after the comments in the iWB2 Learner.ahk script:

 

#Include *i anchor.ahk
#Include *i acc.ahk

 

Actually, the iWB2 Learner.exe was correctly returning values from Classic Active Server Pages (ASP). So by studying your inert code, along with other research, I started to understand the relationship between the frames and the elements. Consequentially I have abandoned the approach above. So far so good ...

 

... and of course that leads to another issue about which I have a question - though I am not sure whether to ask it within this topic or to pop it out as a separate topic - which I will do if that is suggested.

 

Here is the question:

 

I am now able to interact with .asp(s) using the WBGet() function to return the DOM from the ACTIVE IE9 window. However, the .asp(s) I am working with do NOT appear in the ("Shell.Application").Windows collection so it seems I am no longer able to use your IEGet("name.html") function to access the window's/tab's DOM. The hoped for objective was to interact with multiple .asp(s) IE9 windows - reading values from some and writing values to others - without making each of them the ACTIVE window in turn. Any suggestions are appreciated

 

Again, thank you for responding and updating your most excellent code. I've talked with other folks on the forum and they have also studied this code trying to get a handle on COM and the HTML DOM. Not sure where we would be without your insights.



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
    I just put them in the same directory and added these two lines immediately after the comments in the iWB2 Learner.ahk script:

I just put them in the User Library.
 

    ... the .asp(s) I am working with do NOT appear in the ("Shell.Application").Windows collection so it seems I am no longer able to use your IEGet("name.html") function to access the window's/tab's DOM.

Try WBGet.



jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

Jethrow,

 

Thank you for the timely response. Hopefully I am on the verge of finding out that I have more to learn about the WBGet() function icon_smile.gif

 

As noted in the first sentence of my question, the WBGet() function has indeed performed well - but in my experience - has been limited to returning the DOM for the active foreground window under Windows 7 with IE9. This in sharp contrast to the IEGet() function which has been returning any available window or tab, foreground or background, that appears in the  ("Shell.Application").Windows collection.

 

; This works for me with the active foreground window / tab
ie_DOM := WBGet()

; These do NOT work for me with any window / tab
ie_DOM := WBGet("file.html")
ie_DOM := WBGet("tab name")

; This works for me with any window / tab listed in the ("Shell.Application").Windows collection
ie_DOM := IEGet("file.html")

; This no longer works because ASP pages do not appear in the ("Shell.Application").Windows collection :-(
ie_DOM := IEGet("file.asp")

 

So hopefully I am doing something wrong that keeps me from being able to call any IE9 window / tab using the WBget() function. Perhaps I am calling the wrong handle with the function ?



tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007

backtick to escape the modulo


Never lose.
WIN or LEARN.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
... the WBGet() function has indeed performed well - but in my experience - has been limited to returning the DOM for the active foreground window under Windows 7 with IE9. This in sharp contrast to the IEGet() function which has been returning any available window or tab, foreground or background, that appears in the ("Shell.Application").Windows collection.

That just shows your lack of experience. The functions have 2 different approaches - on purpose. IEGet is a more simplistic way of looping through all the IE tabs/windows & finding a name. WBGet actually accesses the webbrowser object from any Internet Explorer_Server (ActiveX) control. Make no mistake, the approach of WBGet is more effective, but both approaches serve a purpose.

Concerning not being able to access a background tab, I propose this:

ie := ComObjCreate("InternetExplorer.Application")
ie.Navigate("www.autohotkey.com/board/index.php?app=core&module=search")
ie.Navigate("www.google.com", 2048)
ie.Visible := true
while ie.busy
   sleep 10
wb := WBGet("ahk_id" ie.hwnd, 2)
wb.document.getElementById("query").value := "Search Term"

 

Now you may ask - is there any way to loop through all the IE Tabs & utilize the approach of WBGet? Good question - yeah:

WinGet, windows, List, ahk_class IEFrame
Loop %windows% {
   hwnd := windows%A_Index%
   WinGet, controls, ControlList, ahk_id %hwnd%
   StringReplace, controls, controls, Internet Explorer_Server, , UseErrorLevel
   if ErrorLevel {
      data .= hwnd "`n"
      Loop %ErrorLevel%
         data .= "  Svr# " A_Index " - " WBGet("ahk_id" hwnd, A_Index).locationName "`n"
      data .= "`n"
   }
}
Msgbox %data%


jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

lol ... we are not worthy icon_smile.gif

I do appreciate the communication by punctuation and you are right, I should have been more specific with - my lack of experience compounded by my lack of knowledge - especially regarding the background workings of the Windows operating system.

At first glance these now appear to be the most valuable code blocks in my world and I will start testing, er, I mean misunderstanding them right away ! Please forgive in advance that I may have to ask for some additional guidance.



jablonsky
  • Members
  • 11 posts
  • Last active: Dec 11 2017 03:27 PM
  • Joined: 24 Nov 2012

Jethrow,

 

It's officially Christmas in January; works like a champ !

 

Dude, there is no way I would have figured this out timely; maybe ever.

 

Thank you so much. :-)