Jump to content

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

Basic Ahk v1.1+ COM Tutorial for Webpages


  • Please log in to reply
138 replies to this topic

Poll: Did this guide help you? (92 member(s) have cast votes)

Did this guide help you?

  1. Ya! COM ftw rawr! (111 votes [86.72%])

    Percentage of vote: 86.72%

  2. No. I am now dumber for having read this... (17 votes [13.28%])

    Percentage of vote: 13.28%

Vote Guests cannot vote
stephenp1983
  • Members
  • 41 posts
  • Last active: Jul 02 2014 03:19 AM
  • Joined: 12 Mar 2012

Forgot to add this is the code associated with the fnShowHideCol function on the page -

 

function fnShowHideCol(iCol) {
  var oSettings = oTable.fnSettings();
  var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
  oTable.fnSetColumnVis(iCol, bVis ? false : true, false);
  oTable.fnAdjustColumnSizing();
};
 



dytanaka
  • Members
  • 4 posts
  • Last active: Jun 27 2014 09:40 PM
  • Joined: 21 Nov 2013

Hi,

 

I am trying to input values into controls using com.  Which I can do if I open up a pointer with a new IE window set the value. But when I use IEGet and IELoad for some reason in IE 11 it does not work.  I tried manipulating the titles to match but that did not work.  Any help would be appreciated.

 

Does anyone have an updated IEGet and IELoad for IE 11?

 

IEGet(Name="")        ;Retrieve pointer to existing IE window/tab

{

    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame

        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 ) && InStr( wb.FullName, "iexplore.exe" )

            Return wb

}

IELoad(wb)    ;You need to send the IE handle to the function unless you define it as global.

{

    If !wb    ;If wb is not a valid pointer then quit

        Return False

    Loop    ;Otherwise sleep for .1 seconds untill the page starts loading

        Sleep,100

    Until (wb.busy)

    Loop    ;Once it starts loading wait until completes

        Sleep,100

    Until (!wb.busy)

    Loop    ;optional check to wait for the page to completely load

        Sleep,100

    Until (wb.Document.Readystate = "Complete")

Return True

}



Justice420
  • Members
  • 2 posts
  • Last active: Jan 17 2014 03:01 PM
  • Joined: 10 Dec 2013

Does anyone have an updated IEGet and IELoad for IE 11?

 

 

I am in the same boat. I've been using that same method for a long time but it's not working with a IE 11. 



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
you can you use jethrow's "WBGet" function from here works fine with IE 11
 
jethrow also posted an updated example of IEReady() here
Helping%20you%20learn%20autohotkey.jpg?d

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

Justice420
  • Members
  • 2 posts
  • Last active: Jan 17 2014 03:01 PM
  • Joined: 10 Dec 2013

right you are, thank you for the help.



Alan_AHK
  • Members
  • 7 posts
  • Last active: Sep 10 2014 02:36 PM
  • Joined: 21 Mar 2013

Please help! Trying to learn all about COM and i'm  doing some very basic work just to understand how things work and what they do. But of course, i'm running into an issue at stage 1! Trying to run the following simple code. Just want to get the InnerText from a specifc ID. Here is my code:

F1::
; ----------------------------------------------------------------------------------------------

 

 

FileSelectFile, Path
X1:= ComObjCreate("Excel.Application")  ; creates a handle to Excel file
X1.Workbooks.Open(Path) ;open an existing file
X1.Visible := True     ; makes excel file selected 'visable'

X1.Sheets("Sheet1").Activate

Pwb := IEGet("Mail - Windows Internet Explorer")

MsgBox % COM_Invoke(pwb,"document.getElementsByID[226].innerHTML", 0)

Pause

 

IEGet(Name="")  ;Retrieve pointer to existing IE window/tab
{
 IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
  Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
  : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
 For Pwb in ComObjCreate( "Shell.Application" ).Windows
  If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
   return Pwb
}

 

I'm getting an errpr saying "Call to non-existant function" ; specifally COM_Invoke....

 

help!!



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

COM_Invoke is from an old COM lib that is not needed anymore with ahk version 1.1+

 

so if the ID of you element is 226 then something like this will work

FileSelectFile, Path

X1:= ComObjCreate("Excel.Application")  ; creates a handle to Excel file
X1.Workbooks.Open(Path) ;open an existing file
X1.Visible := True     ; makes excel file selected 'visable'
X1.Sheets("Sheet1").Activate
 
wb := IEGet("Mail - Windows Internet Explorer")
 
MsgBox % wb.document.getElementByID("226").innertext
return
 
 
; ======== Function ========= 
IEGet(Name="")  ;Retrieve pointer to existing IE window/tab
{
 IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
  Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
  : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
 For Pwb in ComObjCreate( "Shell.Application" ).Windows
  If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
   return Pwb
}

 

Hope it helps


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

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

Alan_AHK
  • Members
  • 7 posts
  • Last active: Sep 10 2014 02:36 PM
  • Joined: 21 Mar 2013

 

COM_Invoke is from an old COM lib that is not needed anymore with ahk version 1.1+

 

so if the ID of you element is 226 then something like this will work

FileSelectFile, Path

X1:= ComObjCreate("Excel.Application")  ; creates a handle to Excel file
X1.Workbooks.Open(Path) ;open an existing file
X1.Visible := True     ; makes excel file selected 'visable'
X1.Sheets("Sheet1").Activate
 
wb := IEGet("Mail - Windows Internet Explorer")
 
MsgBox % wb.document.getElementByID("226").innertext
return
 
 
; ======== Function ========= 
IEGet(Name="")  ;Retrieve pointer to existing IE window/tab
{
 IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
  Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
  : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
 For Pwb in ComObjCreate( "Shell.Application" ).Windows
  If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
   return Pwb
}

Hope it helps

 

 

Thanks Blackholyman! That did help!

 

So its the Index not the ID thats 226 - It actually has no name or ID associated with it.. Any idea how i'd get this as i can't seem to find a "GetElementsByIndex" function..

 

UPDATE:

 

So the following code gave me what i expected direct from the browser:

javascript: alert(document.all[226].innerHTML)

However i'm trying to assign this to a var (instead of displaying it on screen). I've tried the following but can't get it to work...

 

test := wb.document.all[226].innerHTML

msgbox % test



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
I'd need to see all for you code or have a link to the webpage.

Also what version of IE are you using?

Note: when you only edit you post others have no idea that there is new Info in it... May be better to post the new Info in a new post in the topic...
Helping%20you%20learn%20autohotkey.jpg?d

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

errogaht
  • Members
  • 6 posts
  • Last active: Jan 15 2014 07:07 AM
  • Joined: 02 Oct 2013
Hi!
How to delete InternetExplorer.Application cookies? from AHK?
 
 
There is basic:
 
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("facebook.com")
And, if im already logged in ?
 
im need to clear cookies.

im try this variants:
 
1. delete all files in temporyInternetFiles and Cookies folders - NOTHING, folders are both empty, IE restarted- but cookies is used
2. RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351 - NOTHIG , Cookies are unDead!
3. 
wb.Document.cookies := "" - NOTHING , cookies work
4. DllCall("Wininet.dll\InternetClearAllPerSiteCookieDecisions") - nothing, i dont known what it is...
 
MSDN is totally viewed, in 2 hours - there is no basic InternetExplorer.Application .Visible reference, there is TONS of something, but not any about InternetExplorer.Application

 
 
Please help!!!!
 
How to open an InternetExplorer.Application window, and then clear all cookies???

Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
You can try this
 
ClearTracks("Forms")
return


ClearTracks(sCmd) 
{
	ValidCmd 	:=  {Files		:8		; Clear Temporary Internet Files
			    ,Cookies		:2		; Clear Cookies
			    ,History		:1		; Clear History
			    ,Forms		:16		; Clear Form Data
			    ,Passwords		:32		; Clear Passwords
			    ,All		:255		; Clear all
			    ,All2		:4351}		; Clear All and Also delete files and settings stored by add-ons

	If (ValidCmd.haskey(sCmd))
	{
		iCmd := ValidCmd[sCmd] ; Get the integer value
		VarSetCapacity(wCmd,15,0)
		DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "str", iCmd, "int", -1, "str", wCmd, "int", 8)
		DllCall("inetcpl.cpl\ClearMyTracksByProcessW", "Uint", 0, "Uint", 0, "str", wCmd, "int", 0)
	}
	Else
		MsgBox % "Invalid Command -" sCmd "-"
	return ErrorLevel
}
Hope it helps
Helping%20you%20learn%20autohotkey.jpg?d

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

Alan_AHK
  • Members
  • 7 posts
  • Last active: Sep 10 2014 02:36 PM
  • Joined: 21 Mar 2013

I'm having one of those moments where i'm just not thinking clearly and i'm about to bang my head off a wall so if anyone could help on this i'd much appreciate it..
 
so i'm trying to click on something in an iFrame. i have my pointer and everything by wrapping using the ComObj

The following will work:

myIFrame.document.all[179].click()

 

however the index changes from time to time so i need to make it dynamic. I can get the index every time however none of the following seem to want to work (i'll rephrase that - i can't make them work cos i'm doing something wrong or trying to do something that can't be done!)

 

 myIFrame.document.all[review_Docs_Index].click()
 myIFrame.document.all[%review_Docs_Index%].click()
 myIFrame.document.all[' review_Docs_Index '].click()
 myIFrame.document.all[' %review_Docs_Index% '].click()

 

I get errors on the last 2, the first 2 appear to do nothing!

 

Thanks in advance!



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
myIFrame.document.all[179].click()
myIFrame.document.all[review_Docs_Index].click()

These two are the same, assuming review_Docs_Index contains 179.



sv270190
  • Members
  • 19 posts
  • Last active: Jul 30 2017 04:42 PM
  • Joined: 05 Jul 2013

please inform whey the following script is not working

 

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
}
 
wb.document.GetElementsBytagname("input")[7].focus()
sleep 500
 
 
 
 
wb.document.getElementsByTagName("input")[7].value := devathi
sleep 1000
 
wb.document.getElementsByTagName("input")[5].value := guru
sleep 1000
wb.document.getElementsByTagName("input")[6].value := reside
sleep 1000
 
 
 
 
 


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
You have post'ed an UDF in the beginning of your script and you never Call the function so your wb (Webbrowser) object variable never has anything in it...
Helping%20you%20learn%20autohotkey.jpg?d

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