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
rmortensen
  • Members
  • 26 posts
  • Last active: Mar 14 2015 07:41 AM
  • Joined: 08 Sep 2008

When I try to use IWB2 learner on IE 10 /Win 8 Pro the red lines don't reflect the area I'm dragging over.   I remember I had the same issue when I was running IE 8 from XP but am not sure what I did to remedy it.  Anybody have any ideas?  

 

For that matter I've also noticed pointerst to IE10 are not returned with 

Get_IE http://www.autohotke...ction/?p=327575

or 

IE_Get http://www.autohotke...ages/?p=407188 

 

I have exact same problem with IE 10 (except, I'm on a win7 PC)


--
Regards,
R. Mortensen

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

I have exact same problem with IE 10 (except, I'm on a win7 PC)

 

Which problem? If you mean the red lines in iWB2 Learner, I have the same problem. Let me know if you fix it. And, btw, this might be a better thread to talk about that.

 

If yo mean the IEGet() function not working, I would disagree.



Lainie
  • Members
  • 17 posts
  • Last active: Oct 09 2016 03:02 AM
  • Joined: 09 Jan 2010

Hi:
Maybe I am dummier than the average dummy, but I cannot get this to work.  All I want to do, first anyway, is figure out how to get an open instance of IE to become active when it is already open but the IE window is inactive and the tab I want is inactive. My script looks like this:

 

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
} ;written by Jethrow

!j::
Pwb := IEGet("Google") ;Tab name you define can also be a variable
return

 

Am I missing a very basic concept here.  I am using an older version of IE (7) but do have AHK_L and I am using XP op system.  I really want to slowly try and grasp the basics of these concepts, so please help the dummiest of the dummies out.  Thanks in advance!!



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

WinActivate can activate the window. The following demonstrates activating each tab (IE10) without using ctrl+tab:

wb := ComObjCreate("InternetExplorer.Application")
wb.Navigate("autohotkey.com")
wb.Navigate("autohotkey.com/board/", 4096)
wb.Navigate("autohotkey.com/docs/", 4096)
wb.Visible := true
MsgBox, 262144, , Press OK once the webpages are loaded.

Loop {
	ControlGet, hwnd, hwnd, , DirectUIHWND%A_Index%, % "ahk_id" wb.hwnd
	if ErrorLevel
		break
	client := Acc_ObjectFromWindow(hwnd, -4)
	page_tab_list := Acc_Children(client)[1]
} until Acc_Role(page_tab_list) = "page tab list"

for each, child in Acc_Children(page_tab_list)
	if Acc_Role(child) = "page tab" {
		MsgBox % "Press OK to activate tab:`n`n" child.accName(0)
		child.accDoDefaultAction(0)
	}


ZeBuddha
  • Members
  • 45 posts
  • Last active: Jun 16 2016 11:26 AM
  • Joined: 12 Apr 2012

For the IELoad function, is there any way to take into account a password request popup? Nothing fancy, just the regular IE popup. As it is, it gets stuck there.

 

I've been trying to "find"/communicate-with the password prompt in some way aside from visual/winactive, but haven't had much success. My "solution" has been to, instead of using the IELoad function, make an ugly waiting-for-readystate = 4 while-loop. It's neither pretty nor practical and I was wondering if there was a cleaner solution.

if (!WinExist("XYZ")) {
	pWb := ComObjCreate("InternetExplorer.Application") 
	pWb.Visible := true 
	pWb.Navigate(XYZ) 
} else
	pWb := IEGet("XYZ")

while (Pwb.ReadyState <> 4) {
	if (WinExist("XYZ"))
		WinActivate, XYZ
	WinWaitActive, XYZ,,1
	if (Errorlevel) {
		WinWaitActive, Connect to XYZ,,1 ; Check for password prompt
		if (A_Index = 5 && Errorlevel) { ; If no password prompt has shown up & the page hasn't appeared yet after 10s, warn user & "go manual"
			if (!WinExist("XYZ")) {
				MsgBox,, XYZ Error, There's been a problem opening`n`rXXX in Internet Explorer`n`rPlease do so manually then press OK to continue
				WinActivate, XYZ
			}
		} else if (A_index = 10 && !WinExist("XYZ")) {
			PixelSearch,,,125,172,225,185,0x6A240A,1,Fast ; check for existing password in password prompt
			if (!Errorlevel)
				Send {Enter}
			else
				msgBox,, XYZ Login, Please login to XYZ`n`rThen press Ok to continue
		}
	}
}

It ain't pretty, and frankly, it's my first attempt to use COM objects instead of mouse-n-keyboard. My only excuse (for the non-COM part) is that I wrote this some time ago when I'd just started with AHK, and it's one of the reasons I'm trying to "convert" it to COM.



scout
  • Members
  • 134 posts
  • Last active: Jun 11 2015 01:41 PM
  • Joined: 11 Apr 2011

Hi Commnuty,

 

What any others tool instead of ahk web recorder we can use to identify the fields in the IE?

 

Thank you.



scout
  • Members
  • 134 posts
  • Last active: Jun 11 2015 01:41 PM
  • Joined: 11 Apr 2011

Hi! Im getting this error:

Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.Visible := True
TrayTip, Jeneves: , Validando CNPJ - Receita Federal, 10, 17
Pwb.Navigate(ValidaCNPJ)
IELoad(Pwb)
Pwb.Document.All.cnpj.Value := %CNPJ%
Msgbox, 48, Jeneves - Ajuda, Digite o código de verificação
return

 unknown name CNPJ I used the IWB2 Learner and got:



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

you most likely want:

Pwb.Document.All.cnpj.Value := CNPJ


scout
  • Members
  • 134 posts
  • Last active: Jun 11 2015 01:41 PM
  • Joined: 11 Apr 2011

Maybe i was not so clear about my doubt.

 

I have a variable for CNPJ:

 

CNPJ = 123

 

so im using this variable. I noted that my problem should be that this field called cnpj in the IE Page, is inside of a Table or a Form?

 

<INPUT tabIndex=1 onkeyup="SaltaCampo(document.frmConsulta.cnpj, document.frmConsulta.chave, 14, event)" name=cnpj maxLength=14 size=16>

 

Maybe  thats why its not founding a field called CNPJ?

 

Thank you.



scout
  • Members
  • 134 posts
  • Last active: Jun 11 2015 01:41 PM
  • Joined: 11 Apr 2011

I can't even reach the button:

 

<INPUT id=submit1 name=submit1 value=Consultar type=submit>

 

 

tried 

 

Pwb.Document.all.submit1.Click()

Pwb.Document.forms[9].submit1.Click()

Pwb.Document.forms["main"].submit1.Click()

 

 

can't make that work....



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

Hi! Im getting this error:

Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.Visible := True
TrayTip, Jeneves: , Validando CNPJ - Receita Federal, 10, 17
Pwb.Navigate(ValidaCNPJ)
IELoad(Pwb)
Pwb.Document.All.cnpj.Value := %CNPJ%
Msgbox, 48, Jeneves - Ajuda, Digite o código de verificação
return
 unknown name CNPJ I used the IWB2 Learner and got:

 

Maybe i was not so clear about my doubt.
 
I have a variable for CNPJ:
 
CNPJ = 123
 
so im using this variable. I noted that my problem should be that this field called cnpj in the IE Page, is inside of a Table or a Form?
 
<INPUT tabIndex=1 onkeyup="SaltaCampo(document.frmConsulta.cnpj, document.frmConsulta.chave, 14, event)" name=cnpj maxLength=14 size=16>
 
Maybe  thats why its not founding a field called CNPJ?
 
Thank you.

I can't even reach the button:
 
<INPUT id=submit1 name=submit1 value=Consultar type=submit>
 
 
tried 
 
Pwb.Document.all.submit1.Click()
Pwb.Document.forms[9].submit1.Click()
Pwb.Document.forms["main"].submit1.Click()
 
 
can't make that work....


Answer/Example

http://www.autohotke...orial/?p=599965


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

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

scout
  • Members
  • 134 posts
  • Last active: Jun 11 2015 01:41 PM
  • Joined: 11 Apr 2011

Thank you so much.



antonioj84
  • Members
  • 12 posts
  • Last active: Aug 01 2013 01:46 AM
  • Joined: 15 Jun 2013

I am new at autohotkey this a little script I wrote below, can someone or any of the expert give me some guidance, how to to takle the task of changing the script from running at the desktop  to  run instead  in IIS a web server.

 

the challenge is if this code is run with IIS I do not see any equivalent for send ! exct

 

 

; written by Harry Joseph june2013

delay = 300
 

 

;#H::            ;Win+c hotkey to start
RegRead, svcVersion, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Internet Explorer , svcVersion
if (svcVersion = "")

 RegRead, Version, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Internet Explorer , Version
 IEVersion := SubStr(Version, 1 , 1)
}
else
 IEVersion := SubStr(svcVersion, 1 , 2)
; MsgBox IE%IEVersion%
}
 
if( IEVersion = 10){
 Gosub, DoConfigIE
}else if( IEVersion = 9){
 Gosub, DoConfigIE
}else if( IEVersion = 8){
 Gosub, DoConfigIE
}else{
 MsgBox "Unsupported IE version. Kindly upgrade!!!"
}
Gosub, RestartIE
return

RestartIE:
{
 MsgBox, 4, Confirm, Do you want to restart the Internet Explorer?
 IfMsgBox Yes
 {
  Loop
  {
   IfWinExist, ahk_class IEFrame
    WinKill
   else
    break
  }
  Run %A_ProgramFiles%\Internet Explorer\iexplore.exe
  WinWait, ahk_class IEFrame
  WinActivate 
 }
 return
}

DoConfigIE:
{
 ;Open the IE and activate the window
 if WinExist("ahk_class IEFrame")
 {
  WinActivate
 }
 else
 {
  Run %A_ProgramFiles%\Internet Explorer\iexplore.exe
  Sleep, %delay%
  WinWait, ahk_class IEFrame
  WinActivate
 }
 
 

 Sleep, %delay%
 WinWait, ahk_class IEFrame
 Send, {Esc}
 Sleep, %delay%
 Send, !t                    ;click  on tools -> internet option
 Sleep, %delay%
 Send, o
 WinWait, Internet Options

 
 ; #######################General TAB###########################
 
 Send, www.sympatico.ca ;Setting the homepage
 Sleep, %delay%
 Send, {Tab}
 Sleep, %delay%
 ControlGet, OutVar, Checked,, Delete bro&wsing history on exit
 if (OutVar = 0)
  Send, w  ;Checkbox "delete browsing history on exit"  is checked
 ;Delete the history now
 Send, !d
 Sleep, %delay%
 WinWait, A
 ; WinWait, Delete Browsing History 
 Send, !d
 WinWait, Internet Options
 
 ; Setting the diskspace for the webpage
 Sleep, %delay%
 Send, !s
 Sleep, %delay%
 WinWait, A
 Send, !e
 Sleep, %delay%
 Send, !d
 Send, 250
 Send, {Enter}
 Sleep, %delay%
 
 ; #######################Security TAB###########################
 Send, {Ctrl Down}{Tab}{Ctrl up}
 i = 0
 Loop
 {
  Sleep, %delay%
  i++
  Send, {Right}
  ControlGetText, OutputVarText , Static4 ,  Internet Options
  if (i>4)or(OutputVarText = "Trusted sites")
   break
 }
 if(i>4){
  Msgbox Error
  return
 }
 Send, !s
 Sleep, %delay%
 ControlGet, OutVarServerVerif, Checked,, Require &server verification (https:) for all sites in this zone, Trusted sites
 if (OutVarServerVerif = 1)
  Send, !s
 Sleep, %delay%
 Send, !c
 
 Sleep, %delay%
 Send, !c ;Opens Custom Level window
 Sleep, %delay%
 Send, !r
 Sleep, %delay%
 Send, {END}
 Sleep, %delay%
 Send, {Up}
 Sleep, %delay%
 Send, !e
 Sleep, %delay%
 Send, !y
 Sleep, %delay%
 Send, {Enter}
 ; #######################Privacy TAB###########################

; *.manul.ca
; *.manul2.ca
 Send, {Ctrl Down}{Tab}{Ctrl up}
 Sleep, %delay%
 Send, !v ;Opens the Advanced Privacy Settings
 Sleep, %delay%
 ControlGet, OutVarOverRideCookie, Checked,, &Override automatic cookie handling, Advanced Privacy Settings
 if (OutVarOverRideCookie = 0)
  Send, !o
 Sleep, %delay%
 Send, !a
 Sleep, %delay%
 Send, !c
 Sleep, %delay%
 ControlGet, OutVarAlwaysAllow, Checked,, Al&ways allow session cookies, Advanced Privacy Settings
 if (OutVarAlwaysAllow = 0)
  Send, !w
 Sleep, %delay%
 Send, {Enter} ;Window Closes
 
 ;Configure Popup Blocker settings
 ControlGet, OutVar2, Checked,, Turn on Pop-up &Blocker, Internet Options
 if (OutVar2 = 0)
  Send, !b
 Sleep, %delay%
 Send, !e
 Sleep, %delay%
 WinWait, Pop-up Blocker Settings
 Send, !w
 Sleep, %delay%
 Send, www.sympatico.ca
 Sleep, %delay%
 Send, !a
 Sleep, %delay%
 Send, !b
 Sleep, %delay%
 Send, {Down 2}
 Sleep, %delay%
 Send, !c ;Closes the Popup Blocker Settings
 
 Sleep, %delay%
 WinWait, Internet Options
 
 ;Apply the settings and closes the Internet options window.
 Send, !a
 Sleep, %delay%
 Send, {Esc}
 return
}



sen
  • Members
  • 17 posts
  • Last active: Mar 31 2014 07:06 PM
  • Joined: 06 Oct 2013

Can anyone  have idea why I have  this problem:

http://www.autohotke...e8-dosent-work/

 

I couldn't  use Click() on that example

 

 

It's strange problem cos is possibly to read the property but method object COM (at least some of them) doesn't work. And I assumed that they worked well in the past.



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

I was hoping someone could help me with the syntax on a couple of private sites I am trying something with.

 

The first site has multiple columns with input boxes.  On the page is a show/hide column button that brings up a popup with checkboxes.  This allows you to select which columns and input boxes are visible on the main page.  I would like to be able to change the value of the checkboxes after doing a pwb.navigate to the page, so that the columns are automatically selected  Below is an example screenshot from the site, example of what I have tried that does not work, and the code shown using IE HTML Element spy on the checkboxes.  Any help would be appreciated.

From IE Element SPY - 
<INPUT onclick=fnShowHideCol(3) value=3 CHECKED type=checkbox>
<INPUT onclick=fnShowHideCol(11) value=11 type=checkbox>


AHK Code -
Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.visible := true
Pwb.Navigate(url)
IELoad(Pwb)	;You must send the function your Handle for it to work
Pwb.document.All.search_IP.Value := (ipaddress)
Pwb.document.All.25.checked := True

33r3.png