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
  • Guests
  • Last active:
  • Joined: --
When trying to use 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

I get this error:

Error at line 6:
Line Text: For Pwb in ComObjCreate( "Shell.Application" ).Windows
Error: This line does not contain a recognized action
the program will now exit.


any ideas? trying to use with IE9

Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Try downloading and use autohotkey_L its first on the download page

Hope it helps

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

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

leehong1
  • Validating
  • 403 posts
  • Last active: May 19 2019 03:12 PM
  • Joined: 24 Nov 2008
I can't get "f2"(only give blank IE page) and "f3"(cannot navigate on open instance of IE) to work
f1::

Pwb := ComObjCreate("InternetExplorer.Application")

Pwb.Visible := True

Pwb.Navigate("www.autohotkey.com")

return



f2::

Pwb := ComObjCreate("InternetExplorer.Application")

Pwb.Visible := True

Pwb := IEGet()

Pwb.Navigate("www.autohotkey.com")

return



f3::

Pwb := IEGet()

Pwb.Navigate("www.autohotkey.com")

return



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



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"

needs to say 'about:Tabs'
Helping%20you%20learn%20autohotkey.jpg?d

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

leehong1
  • Validating
  • 403 posts
  • Last active: May 19 2019 03:12 PM
  • Joined: 24 Nov 2008
@Blackholyman ....
I have this in my script
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
But when I copy to this forum it shows...
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
I am having this showing up in the forum....
[*:3n5tguxe]Chris Malet for creating AutoHotkey

this happens after the format change in this forum

stephenp1983
  • Members
  • 41 posts
  • Last active: Jul 02 2014 03:19 AM
  • Joined: 12 Mar 2012
Thanks for this tutorial it's been very helpful so far. I have a question hopfully somone can help me with. I've been able to use this to put a specified value into a inputbox on a webform using like so - Pwb.document.All.txtDescription.Value := "testing" I'm trying to figure out how I can set the value of a drop down box on this form as well. As you can see from the code below from the page there are 4 predefined values in the drop down box, which defaults to "select item" I would like to be able to automate changing this to one of the other values such as "research"

I've tried a few different ways with this format - Pwb.document.All.cboActivityTypes.Value :=, but I can't see to get it working.


<select name="cboActivityType" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;cboActivityType\&#39;,\&#39;\&#39;)&#39;, 0)" id="cboActivityType" class="DropDownStyle" style="width:250px;position: relative">
<option selected="selected" value="{Select Item}">{Select Item}</option>
<option value="3">Assignment</option>
<option value="9">EmployeeSupport</option>
<option value="4">Research</option>


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

Sorry im not sure but f1 and f3 works for me, and under f2 the IEGet() Function is not needed as pwb := ComObjCreate() already stores a web browser object in pwb

@stephenp1983

Trie this out
html =
(
<!DOCTYPE html>
<html>
<body>
<select name="cboActivityType" id="cboActivityType" class="DropDownStyle" style="width:200px;position: relative">
<option selected="selected" value="{Select Item}">{Select Item}</option>
<option value="3">Assignment</option>
<option value="9">EmployeeSupport</option>
<option value="4">Research</option>

</body>
</html>
)
time := 3
Gui, Add, ActiveX, w250 h100 vWB, Shell.Explorer
Gui, Add, text, w250 vtext, %time%
wb.Navigate("about:blank")
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
sleep 100
wb.document.write(html)
Gui, Show,, BuildAScript
SetTimer, downing, 1000
return

downing:
if (time != 0)
{
time-=1
ControlSetText, static1, %time%, BuildAScript
}
else
{
SetTimer, downing, off
ControlSetText, static1, wb.document.all.cboActivityType.selectedIndex:=2, BuildAScript
wb.document.all.cboActivityType.selectedIndex := 2 ; Note - you could use .value := 9
}
return

GuiClose:
ExitApp

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

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

stephenp1983
  • Members
  • 41 posts
  • Last active: Jul 02 2014 03:19 AM
  • Joined: 12 Mar 2012
Thank you very much... That worked perfectly.

leehong1
  • Validating
  • 403 posts
  • Last active: May 19 2019 03:12 PM
  • Joined: 24 Nov 2008
@Blackholyman ....thks
1) for "f2"...remove the IEGET()...ok

2) jethrow help me with this code....for "f3"(focus on open webpage)
wb := WBGet()
MsgBox % wb.document.documentElement.outerHTML
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)
}
}
}


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012
Is this thread all about MS Internet Explorer or it can also be used with Mozilla Firefox?

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


MS Internet Explorer but there may be some plugin that will make it work on fire Fox unsure...
Helping%20you%20learn%20autohotkey.jpg?d

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

Guest
  • Members
  • 2 posts
  • Last active: Nov 21 2012 11:24 AM
  • Joined: 21 Nov 2012
ignoer it...posted the topic without update...so, modifying..

Guest
  • Members
  • 2 posts
  • Last active: Nov 21 2012 11:24 AM
  • Joined: 21 Nov 2012
Can any one help how to pass text to an element which is in a frame in a webpage.

When I used the iWB Learner, it given the following info. I am using AutoHotKey_L.

Frame.# Index name id
FRAME.1 10 patmgr patmgr


OuterHTML

<INPUT tabIndex=130 maxLength=9 size=12 name=account>


I am trying to pass the Account# to the account text box, but not able to do.

Pwb.document.All.account.Value := "123456"


how ever i am able to pass this using COM and iWeb
iWeb_setDomObj(pwb,"account","154833","10")

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
pwd.document.parentwindow.frames("patmgr").contentwindow.document.all.account.value := "123456"
Never lose.
WIN or LEARN.

faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
@tank: shouldn't it be pwd.document.parentwindow.frames("patmgr").document.all.account.value := "123456" ?
and perhaps it is time to update your signature as ahk_l is now ahk ;-)