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
sv270190
  • Members
  • 19 posts
  • Last active: Jul 30 2017 04:42 PM
  • Joined: 05 Jul 2013

kindly guide me how to use ieget() or something like  and access the  following existing active web page in internet explorer

 

"URL = http://www.roboform....als/form-filler"   ; already open existing active web page
 
 
{
code using  ieget()                                      ;  need your help
}
 
 
 
then the following codes comes
 
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
@sv270190

http://www.autohotke...rm/#entry632946
Helping%20you%20learn%20autohotkey.jpg?d

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

Will_Automate_It
  • Members
  • 4 posts
  • Last active: Feb 13 2014 05:38 PM
  • Joined: 26 Apr 2013

Question:

 

I've used the wbget() function to get two com objects from two different browser tabs. wb1 and wb2. I can get and put data into either one. 

 

What I'm trying to do is make either tab the active one in my browser.  

 

In my desperate attempt, I've tried wb1.activate , wb1.select , even wb1.focus().  ( Don't laugh )

 

I was also going to try looping through and using control tab to activate each tab one at a time, then use wbget and "compare" each active tab to wb1 until it matched.

But that's too slow and I'm hoping there's a more elegant solution.

 

 

 

Comment:

I'd like to thank the authors of this thread and the wbget() function. Great stuff !



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

In my desperate attempt, I've tried wb1.activate , wb1.select , even wb1.focus().  ( Don't laugh )

 

A desperate attempt is better than just begging for help. The issue with what you tried is those methods belong to webpage elements, not the window/webbrowser object. There is no direct HTML DOM method for activating a specific IE tab, that I'm aware of.

 

However, ACC (or better yet, UIA) provides a way of accomplishing this by accessing the tab element, then calling DoDefaultAction (the DefaultAction being Press). The problem with this method is finding a way to access the tab element that doesn't change with each new release of IE.

 

Anyways, here are some links that might help:

 

Accessible Info Viewer

WinActivate on a specific IE browser tab



Will_Automate_It
  • Members
  • 4 posts
  • Last active: Feb 13 2014 05:38 PM
  • Joined: 26 Apr 2013

jethrow thanks for the response.

 

I noticed that in that second link, the first line of the tab activate function looks like this:

 

         TabActivate(hwnd, tabName) 

 

Question 1. I'm assuming the hwnd applies to the browser window, but that it can have multiple tabs with the same tabName. Is this true?

 

Question 2. To make that function work, would I need to copy some acc function from somewhere and place it in my ahk?



Will_Automate_It
  • Members
  • 4 posts
  • Last active: Feb 13 2014 05:38 PM
  • Joined: 26 Apr 2013

Please pardon my elementary questions.

 

I'm trying to get AHK to click the Add button that comes from the table whose html is listed below....

When I hover my mouse over the Add button on the page, the status bar says goform/new_bwp

 

I tried           orig.document.all.Tags("input")["new_bwp"].click()                   but that method doesn't work on that item.

 

 

</TABLE>
</DIV>
</CENTER>
<TABLE ALIGN="center" BORDER="0"                     CELLPADDING="0" CELLSPACING="0"                     WIDTH="650" BGCOLOR="snow">
<TABLE STYLE="table-layout:fixed ; width:650px" ALIGN="center" CELLSPACING="5" BGCOLOR="snow"><TR><TD COLSPAN="7" HEIGHT="50"        ALIGN="center">
<FORM ACTION="goform/new_bwp" METHOD="POST">
<INPUT type="hidden" name="hidden"        value="hidden">
<INPUT type="submit" name=new_bwp         value="Add">
</FORM>
</TD></TR>
</TABLE>


sv270190
  • Members
  • 19 posts
  • Last active: Jul 30 2017 04:42 PM
  • Joined: 05 Jul 2013
can we modify   IEGET(name="") function
so that  regardless of the title of window,  it access the active window
 
 
like this
 
 
 
wb := ieget("")
 
ieget(wb)
 
codes
codes
 
 
 
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
 

 }


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

@ sv270190

http://www.autohotke...rm/#entry634449
Helping%20you%20learn%20autohotkey.jpg?d

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

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

 f7::
 
 {
 
;wb := ieGet()
 

wb := ieget()
 

ieget(wb)
 
wb.document.GetElementByid("userid").focus()
 
wb.document.GetElementByid("userid").value := "sv270190"
 
wb.document.GetElementByid("solid").value := "852456svs"
 
 
 }
 
return
 
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
}
 
but this work
 


 f4::
 
 {
 
 
 

wb := ieget("Finacle Prelogin")
         
ieget(wb)
 
wb.document.GetElementByid("userid").focus()
 
wb.document.GetElementByid("userid").value := "sv270190" 
 
wb.document.GetElementByid("solid").value := "852456svs"
 
 
 }
 

return


autu
  • Members
  • 9 posts
  • Last active:
  • Joined: 12 Apr 2014
#7::
wb :=IEGet("Google") ;IE instance already open and tab named google exists

Website = site:autohotkey.com tutorial
wb.Document.All.elements[161].Value := Website
wb.Document.All.btnG.Click()
IELoad(wb)
wb := ComObjCreate("InternetExplorer.Application") ;create a IE instance
wb.Visible := True
URL = Google.com
wb.Navigate(URL)
IELoad(wb)
Website = site:autohotkey.com tutorial
wb.Document.All.q.Value := Website
sleep 2000
wb.Document.All.btnG.Click()
IELoad(wb)
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 wb in ComObjCreate( "Shell.Application" ).Windows
        If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
            Return wb
} ;written by Jethrow

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
}
The first time  it run normally 
the second  time there are popups ,Line 3 can not be assigned


autu
  • Members
  • 9 posts
  • Last active:
  • Joined: 12 Apr 2014

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

}

I have the same problem with you  IE11



autu
  • Members
  • 9 posts
  • Last active:
  • Joined: 12 Apr 2014

you can you use jethrow's "WBGet" function from here works fine with IE 11
 
jethrow also posted an updated example of IEReady() here

My English is poor, who can help me posted a corrected code,  thanks advance

 

win7+IE11



MrGibbage
  • Members
  • 8 posts
  • Last active: Nov 07 2014 03:28 PM
  • Joined: 18 Nov 2009

I can interact with web pages like google, so I have AHK set up correctly. I am trying to click rows one at a time down a table on a web page. The table layout is at the bottom of this post. I first wanted to try clicking just one row, then I will loopify it to click all of them. I tried

 

wb := WBGet("Pretzel - Reports") ;IE instance already open and tab named "Pretzel - Reports" exists
wb.Document.GetElementById("51C94798783648B68492CF9B991F9B83").Click()
 
The javascript that runs on the page highlights the row that is clicked, so I can easily see if that worked. But it is not highlighting, so I don't think it is working.
 
Is there something that I missed (probably something obvious).
 
Also where is the list of all of the functions I can run on the wb object? What type of object is it, anyway?
 
Here's the html for the table:

http://pastebin.com/Gd0ETvav

By the way, this is not really about pretzels. I had to obfuscate things because of business sensitivities!


za3root
  • Members
  • 97 posts
  • Last active: Sep 25 2015 09:11 PM
  • Joined: 10 Feb 2015

Thanks for the great tutorial. Every thing was fine until the college girl example. I felt that it was fast paced afterwards. 

 

I am facing a small problem whenever I use the "wb.Visible := True". It is telling me that the variable contains an illegal character. How to solve this problem??

 

Thanks in advance :D



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

You need the version from http://ahkscript.com
Helping%20you%20learn%20autohotkey.jpg?d

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