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
PineCones
  • Guests
  • Last active:
  • Joined: --
This was incredibly helpful to me. I just have one issue.

I have been using this code to click a button a page, the button has a text of "This Button" and the ID shows as 116, so I use this code:

Pwb.Document.All.116.click()

Works great. So I reload the page and suddenly, that same button is no longer 116 it's not 114 and so my script doesn't work. Yet the button name is still "This Button".

Is there any other way to click or track that button so it will works even if the "116" changes to "114" or no?

Mickers
  • Members
  • 1239 posts
  • Last active: Sep 25 2015 03:03 PM
  • Joined: 11 Oct 2010
I think this post would be helpful to you: http://www.autohotke...pic.php?t=71580 The ID is dynamic as in it changes everytime you load the page you will either have to reference it by name, like you said, or use it's location on the page. Hope this helps! :wink:

almw59
  • Members
  • 14 posts
  • Last active: Jun 23 2011 06:12 PM
  • Joined: 06 May 2009
Tried to control a web page as suggested in the post but got the access denied werror when running following code. Any ideas - note I am logged in as an adminsistrator on the pc.

The error occurs on both the lines starting Pwb.Document

Pwb := ComObjCreate("InternetExplorer.Application") ;create a IE instance
Pwb.Visible := True
Pwb.Navigate("Google.com")
IELoad(Pwb)

Pwb.Document.All.q.Value := "site:autohotkey.com tutorial"
Pwb.Document.All.btnG.Click()
IELoad(Pwb)


  • Guests
  • Last active:
  • Joined: --
Mickers,

It would be great if you continued your tutorial. You explain things very well and helped me alot.

Mickers
  • Members
  • 1239 posts
  • Last active: Sep 25 2015 03:03 PM
  • Joined: 11 Oct 2010
I've had some spare time recently. Mabye I'll put something together. :wink:

awannaknow
  • Members
  • 372 posts
  • Last active: Mar 03 2019 05:18 AM
  • Joined: 14 Jun 2009
+1 :lol:

Mickers,

It would be great if you continued your tutorial. You explain things very well and helped me alot.


Your scripts online or anything you'll need online for free with 0hna.tk  like: Zero $ Hosting No Ad Free Online Hosting
Remove comments and blank lines in AHK code

Mickers
  • Members
  • 1239 posts
  • Last active: Sep 25 2015 03:03 PM
  • Joined: 11 Oct 2010

+1 :lol:

Mickers,

It would be great if you continued your tutorial. You explain things very well and helped me alot.

Your wish has been granted. Check out the second post of this thread for a brand new section.

Feedback is appreciated!!!

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

Woopsy did you get an error? Items in the collection that are blank cause a COM error but don't actually hurt anything.

You are mistaken. Collections are Zero-based.

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Feedback is appreciated!!!

I have spend an hour or 2 each day for several days trying to do one thing.

Click on a particular link on foxnews.com

Using your latest tutorial (post 2 of this thread) I was able to do it in minutes.

You are providing an excellent starting point to using AutoHotkey_L COM.

thanks very much for taking the time to make this tutorial.

DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

Mickers
  • Members
  • 1239 posts
  • Last active: Sep 25 2015 03:03 PM
  • Joined: 11 Oct 2010
@DataLife
Your very welcome!

Woopsy did you get an error? Items in the collection that are blank cause a COM error but don't actually hurt anything.

You are mistaken. Collections are Zero-based.

Hmm could you explain to me why when the .InnerText property returns an empty string I get a COM error? Also the last item in the collection yields an error as well and I haven't been able to fathom why.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
For IE in ComObjCreate("Shell.Application").Windows ; for each open window
	If	InStr(IE.FullName, "iexplore.exe")
		break

This is bound to throw a lot of users off since most will tend to have more than one tab open. It's probably a good idea to show folks how to throw an additional check in there to ensure they're grabbing the right window. Like matching the window's title (LocationName) or url (LocationURL).

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

Hmm {...}Also the last item in the collection yields an error as well and I haven't been able to fathom why.

Mickers, Jethrow is trying to lead you to watter but i wanna make you drink it. All collections are 0 based. instead of a_index you should be using a_index-1 this is why your last item always returns an error. Blank innertext should not return an error unless that element do not support it
for example this should be like this
Loop % Links.Length ; check each link
If ((Link := Links[[color=red]a_index-1[/color]].InnerText) != "") ; if the link is not blank
Msg .= A_Index . " " . Link . "`n" ; add item to the list
MsgBox % Msg ; display the list

Never lose.
WIN or LEARN.

Mickers
  • Members
  • 1239 posts
  • Last active: Sep 25 2015 03:03 PM
  • Joined: 11 Oct 2010
@tank
Doh! :shock:

Sometimes simple things just go right over my head. :lol:

@sinkfaze
I'll update it and add some comments. Confusion is never a good thing. :wink:

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Additionally, I suggest -- and so does Sean -- not turning off the ComError on code you post - unless it's necessary.

  • Guests
  • Last active:
  • Joined: --

For IE in ComObjCreate("Shell.Application").Windows ; for each open window
If InStr(IE.FullName, "iexplore.exe") ; check if it's an ie window
break ; keep that window's handle
; this assumes an ie window is available. it won't work if not

This is the first I seen IE used in place of PWB or WB.

Is there any kind of unofficial standard when to use what?

Maybe...
PWB (Autohotkey Basic)
WB (Autohotkey_L)
IE (? Would it be better to leave it as WB)

Changing to IE threw me off. I used IE to use an existing IE window instead of creating a new one, but forgot to change WB to IE throughout the rest of my script

I use this code to easily change between creating a new IE window or using an existing one.
CreateNewIeObject := 0
if CreateNewIeObject = 1 ;create new IE windows
 WB := ComObjCreate("InternetExplorer.Application")
else ;use Existing IE window
 {
  For WB in ComObjCreate("Shell.Application").Windows ; for each open window
  If InStr(WB.FullName, "iexplore.exe") ; check if it's an ie window
   break ; keep that window's handle
 }