Control and get element under IE tab and frames...

Get help with using AutoHotkey and its commands and hotkeys
Zelio
Posts: 275
Joined: 30 Sep 2013, 00:45
Location: France

Control and get element under IE tab and frames...

15 Apr 2015, 17:08

I try to get access inside of others tab, sorry, I don't know what to do, and I am very unskilled with this stuff... I have an obligation of using tab, for merge and save a lot of ressources...

I build the browser like this:

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true

loop % number
{
if (a_index = 1)
	wb.Navigate(link)
else
	wb.Navigate2(link, 2048)
}
...but I have only acces of the first tab, what I have to do for the others ? Something to get and store for a wb.tab[x] ?

Code: Select all

wb.document.parentWindow.frames["X"].frames["Y"].document.getElementById("Z").click()
Thanks a lot in advance, I want to be more present, but my life is currently unstable, I miss you all but seems the ahk futur will be gorgeous (still time to read)...
Zelio
Posts: 275
Joined: 30 Sep 2013, 00:45
Location: France

Re: Control and get element under IE tab and frames...

16 Apr 2015, 09:43

I found an old thread, I will investigate, thanks to Jethrow, http://www.autohotkey.com/board/topic/8 ... iexplorer/

Code: Select all

navOpenInBackgroundTab := 4096

; Load IE with 3 tabs
wb1 := ComObjCreate("InternetExplorer.Application")
wb1.Visible := True
wb1.Navigate("www.google.com")
wb1.Navigate("www.google.com", navOpenInBackgroundTab)
wb1.Navigate("www.google.com", navOpenInBackgroundTab)

; get WebBrowser Object for Internet Explorer_Server 2 & 3
Loop 2 {
	i := A_Index+1
	while Not wb%i%
		wb%i% := WBGet("ahk_id" wb1.hwnd, i)
}

; wait for all tabs to load
while wb1.busy or wb2.busy or wb3.busy
	sleep 10


Loop 3
	wb%A_Index%.Document.All.q.Value := "Hello" ; enters Hello in google search area
 , wb%A_Index%.document.GetElementById("btnK").click()




WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs
	static	msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
	,	IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp
;	,	IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
	SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
	if (ErrorLevel != "FAIL") {
		lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
		if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
			DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
			return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
		}
	}
}
User avatar
TLM
Posts: 1418
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: Control and get element under IE tab and frames...

16 Apr 2015, 09:49

I was also able to get it to work with WBGet() but the tab has to be active

Code: Select all

TabName = AutoHotkey - Windows Internet Explorer
Links := [ "google.com", "ahkscript.org", "autohotkey.com" ]

wb := ComObjCreate("InternetExplorer.Application"), wb.Visible := true

For i, Link in Links
{
    wb.Navigate2( Link, ( i=1 ? "": 2048 ) ) 
    Wait( wb )
}

For Window in ComObjCreate("Shell.Application").Windows
{
    if InStr( Window.Parent.Fullname, "iexplore.exe" )
    {
        DetectHiddenWindows, On
        CurrentTabName := Window.LocationName " - " Window.Name
        WinActivate % CurrentTabName
        WinWaitActive % CurrentTabName

        if ( CurrentTabName = TabName )
        {
            ieObj := WBGet( CurrentTabName )
            Break
        }
    }
}

Msgbox % ieObj.document.getElementsByTagName( "*" ).length " tags found on " CurrentTabName " tab."
            
Return

ESC::ExitApp	; <-- Press escape to exit.

Wait( obj, int = 500 )
{
    While  !(rs~="4{" int "}\b")
    {
        rs .= obj.ReadyState
    }
}

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
edit: I tried wb1.hwnd too but it didn't work will try your approach and see what the difference is :)
for direct help, tweet at me: https://twitter.com/CW_DTech
User avatar
TLM
Posts: 1418
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: Control and get element under IE tab and frames...

16 Apr 2015, 10:41

ok got it to work although I had to wait for each tab to load 1st

Code: Select all

TabName = AutoHotkey - Windows Internet Explorer
Links := [ "google.com", "ahkscript.org", "autohotkey.com" ]

wb := ComObjCreate("InternetExplorer.Application"), wb.Visible := true

For i, Link in ( Links, wb_ := [] )
{
    wb.Navigate2( Link, ( i=1 ? "": 4096 ) ), Wait( wb, 800 )
    wb_[ i ] := WBGet( "ahk_id" wb.hwnd, i )
}

While ( CurrentTabName != TabName )
    ieObj := wb_[ a_index ], CurrentTabName := wb_[ a_index ].LocationName " - " wb_[ a_index ].Name
    
Msgbox % ieObj.document.getElementsByTagName( "*" ).length " tags found on " CurrentTabName " tab."
return

ESC::ExitApp	; <-- Press escape to exit.

Wait( obj, int = 500 )
{
    While  !(rs~="4{" int "}\b")
    {
        rs .= obj.ReadyState
    }
}

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
Still needs some modification to find tabs not created by the script.
for direct help, tweet at me: https://twitter.com/CW_DTech

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Bort P, Google [Bot], Marcosa1020, SOTE and 196 guests