Click on specific button of existing web page.

Get help with using AutoHotkey and its commands and hotkeys
Toni Osuna
Posts: 5
Joined: 18 Jul 2019, 19:36

Click on specific button of existing web page.

19 Jul 2019, 13:33

Hi to all,
I just starting using AutoHotkey and I really need your help.

I need to click in a web page button (alredy open page), I have been searching for a solution but all I found is a script that open the browser, then open a page and then click on the button, this is that script (thanks to user Sjc1000):

Code: Select all

Pwb:= ComObjCreate( "InternetExplorer.Application" )													; Creates the ComObj
Pwb.Navigate("www.AutoHotkey.com")																		; Navigates to AutoHotkey.com
Pwb.Visible:= True																						; Shows the IE app

While ( Pwb.Busy || Pwb.ReadyState != 4 )																; Waits for the webpage to finish loading
	Sleep 10																							;	|

value := ""																								; Creates the variable ( not needed )

While ( value <> "Forums" )																	; Loops through the elements, until its innerText matches.
	value := Pwb.document.getElementsByTagName( "a")[ A_Index - 1].innerText, index := A_Index -1		; Gets the value, and stores the Index

Pwb.document.getElementsByTagName( "a")[ index].Click()													; Clicks on the Community Forum link.
The string "Forums" is the label of the button, what I understand is that the script searches the entire screen for the element labeled "Forums", when it finds it it stops then clicks on it. But it looks for the elements in the Pwb object, here is where I'm stuck I do not know how to create the Pwb object with an existing Web page.

I need a script that works in an existing web page because before do the click in the button it is necesary insert a serial number (always different number) and I can't figure out how to do it, hope you can help me :D. Thank you..
Toni Osuna
Posts: 5
Joined: 18 Jul 2019, 19:36

Re: Click on specific button of existing web page.

22 Jul 2019, 12:14

Thank you aifritz, but the Acc Library is not able to download https copy.com /oiLspOmEi0xVCg1F/Acc.ahk?download=1.
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Click on specific button of existing web page.

22 Jul 2019, 12:54

Code: Select all

/*
$:=new iWebBrowser2
pwb:=$.oIE_get("portal")
$.Activate(pwb)
*/

class iWebBrowser2 {

    oIE_new(ByRef sURL = "about:blank", ByRef sTitle = "", ByRef iHWND = "", ByRef sHTML = "", bVisible = true)
        {
        this.isInstalled()
        oIE := ComObjCreate("internetexplorer.application")
        oIE.Visible := bVisible
        if sURL
            oIE.Navigate(sURL)
        return oIE
        }

    oIE_get( ByRef sTitle = "", ByRef iHWND = "", ByRef sURL = "", ByRef sHTML = "" )
        {
        this.isInstalled()
        ;~ this function is pointless if no instance of IE is open
        ;~ one edit you might make is to have this function open IE and maybe go to the home page
        if ( !winexist( "ahk_class IEFrame" ) )
            {
            MsgBox, 4112, NO IE Window Found, The Macro will end
            ExitApp
            }
        
        if sTitle
            this.clean_IE_Title( sTitle ) 
        ;; ok this function should look at all the existing IE instances and build a reference object
        ; List all open Explorer and Internet Explorer windows:
        oIE := Object()
        matches := 0
        
        for window,k in ComObjCreate("Shell.Application").Windows
            if ( "Internet Explorer" = window.Name)
                {
                possiblematch := true
                if !window.document
                    continue
                pdoc := this.pDoc(window)
                if ( possiblematch && sTitle && !instr( pdoc.title, sTitle ) )
                    possiblematch := false
                
                if ( possiblematch && sHTML && !instr( pdoc.documentelement.outerhtml, sHTML ) )
                    possiblematch := false
                
                if ( possiblematch && sURL && !instr( pdoc.url, sURL ) )
                    possiblematch := false
                
                if ( possiblematch && iHWND > 0 && window.HWND != iHWND )
                    possiblematch := false		
                    
                if ( possiblematch )
                    {
                    ;~ windowsList .= k " => " ( clipboard := window.FullName ) " :: " pdoc.title " :: " pdoc.url "`n"
                    matches++
                    sTitle := pdoc.title
                    sURL := pdoc.url
                    iHWND := window.HWND
                    sHTML := pdoc.documentelement.outerhtml
                    oIE := window
                    }
                ObjRelease( pdoc )
                }
                
        if ( matches > 1 )
            {
            MsgBox, 4112, Too many Matches ,  Please modify your criteria or close some tabs/windows and retry
            ExitApp
            }
            
        return oIE
        }

    FindbyText(pwb, needle)
        { ;; returns the element with the text in it        
        try rng:=this.pdoc(pwb).body.createTextRange()
        try rng.findText(needle)
		return try rng.parentElement()
	    }

/*

    FindbyText(pwb, needle)
        { ;; returns the element with the text in it        
        try rng:=pwb.document.body.createTextRange()
        try rng.findText(needle)
		return try rng.parentElement()
	    }


*/

    Activate(pwb) 
        { 
        DllCall("LoadLibrary", "str", "oleacc.dll") 
        HWND:=pwb.HWND
        DetectHiddenWindows, On 
        WinActivate,% "ahk_id " HWND
        WinWaitActive,% "ahk_id " HWND,,5
        ControlGet, hTabBand, hWnd,, TabBandClass1, ahk_class IEFrame
        ControlGet, hTabUI  , hWnd,, DirectUIHWND1, ahk_id %hTabBand% 
        
        VarSetCapacity(CLSID, 16)
        nSize=38
        wString := sString := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
        if(nSize = "")
            nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
        VarSetCapacity(wString, nSize * 2 + 1)
        DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1)
        DllCall("ole32\CLSIDFromString", "Uint",&wString , "Uint", &CLSID)
        
        If   hTabUI && DllCall("oleacc\AccessibleObjectFromWindow", "Uint", hTabUI, "Uint",-4, "Uint", &CLSID , "UintP", pacc)=0 
            { 
            pacc := ComObject(9, pacc, 1), ObjAddRef(pacc)
            Loop, %   pacc.accChildCount 
                If   paccChild:=pacc.accChild(A_Index) 
                    If   paccChild.accRole(0+0) = 0x3C 
                        { 
                        paccTab:=paccChild 
                        Break 
                        } 
                    Else   ObjRelease(paccChild) 
            ObjRelease(pacc) 
            } 
        If   pacc:=paccTab 
            { 
            Loop, %   pacc.accChildCount
                If   paccChild:=pacc.accChild(A_Index) 
                    If   paccChild.accName(0+0) = sTitle   
                        { 
                        ObjRelease(pwb)
                        paccChild.accDoDefaultAction(0)
                        ObjRelease(paccChild) 
                        Break 
                        } 
                    Else   ObjRelease(paccChild) 
            ObjRelease(pacc) 
            }  
        WinActivate,% sTitle
        } 


    isInstalled()
        {
        Static IE_path
        
        ;; find where windows believes IE is installed
        ;; certain corp installs may have this in other than expected folders
        if !IE_path
            RegRead, IE_path, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE
        ;~ MsgBox % IE_path
        ;; Perhaps policies prevent reading this key
        if ( ErrorLevel || !IE_path )
            IE_path := "C:\Program Files\Internet Explorer\iexplore.exe"
        
        ;; make sure it installed
        if !FileExist( IE_path )
            {
            MsgBox, 4112, Internet Explorer Not Found, IE does not appear to be installed`nCannot continue `nClick OK to Exit!!!
            ExitApp
            }
        } 

    pDoc(oIE)
        {
        return this.IHTMLWindow2_from_IWebDOCUMENT( oIE.document ).document
        }

    clean_IE_Title( ByRef sTitle = "" ) 
        {
        return sTitle := RegExReplace( sTitle ? sTitle : this.active_IE_Title(), this.IE_Suffix() "$", "" )
        }

    IE_Suffix() 
        {
        static sIE_Suffix
        if !sIE_Suffix
            {
            ;; HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
            RegRead, sIE_Suffix, HKCU, Software\Microsoft\Internet Explorer\Main, Window Title ;, Windows Internet Explorer,
            sIE_Suffix := " - " sIE_Suffix
            }
        return sIE_Suffix
        }

    active_IE_Title() ;; returns the title of the topmost browser if exists from the stack
        {
        sTitle := "NO IE Window Open"
        if winexist( "ahk_class IEFrame" )
            {
            titlematchMode := A_TitleMatchMode
            titlematchSpeed := A_TitleMatchModeSpeed
            SetTitleMatchMode, 2	
            SetTitleMatchMode, Slow
            WinGetTitle, sTitle, %sIE_Suffix% ahk_class IEFrame
            SetTitleMatchMode, %titlematchMode%	
            SetTitleMatchMode, %titlematchSpeed%
            }
        return RegExReplace( sTitle, this.IE_Suffix() "$", "" )
        }
        
        
        
    IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT )
        {
        static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"  ; IID_IHTMLWindow2
        return ComObj(9,ComObjQuery( IWebDOCUMENT, IID_IHTMLWindow2, IID_IHTMLWindow2),1)
        }

    IWebDOCUMENT_from_IWebDOCUMENT( IWebDOCUMENT ) ;bypasses certain security issues
        {
        return this.IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT ).document
        }

    IWebBrowserApp_from_IWebDOCUMENT( IWebDOCUMENT )
        {
        static IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"  ; IID_IWebBrowserApp
        return ComObj(9,ComObjQuery( this.IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT ), IID_IWebBrowserApp, IID_IWebBrowserApp),1)
        }

    IWebBrowserApp_from_Internet_Explorer_Server_HWND( hwnd, Svr#=1 ) 
        {               ;// based on ComObjQuery docs
        static msg := DllCall( "RegisterWindowMessage", "str", "WM_HTML_GETOBJECT" )
            , IID_IWebDOCUMENT := "{332C4425-26CB-11D0-B483-00C04FD90119}"
        
        SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, ahk_id %hwnd%
        
        if (ErrorLevel != "FAIL") 
            {
            lResult := ErrorLevel
            VarSetCapacity( GUID, 16, 0 )
            if DllCall( "ole32\CLSIDFromString", "wstr", IID_IWebDOCUMENT, "ptr", &GUID ) >= 0 
                {
                DllCall( "oleacc\ObjectFromLresult", "ptr", lResult, "ptr", &GUID, "ptr", 0, "ptr*", IWebDOCUMENT )
                return  this.IWebBrowserApp_from_IWebDOCUMENT( IWebDOCUMENT )
                }
            }
        }
}
While this lib is overkill, to get the pwb just do this

Code: Select all

ie := new iWebBrowser2
pwb := ie.oIE_get() ;; current IE
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

22 Jul 2019, 14:33

tank wrote:

Code: Select all

pdoc := this.pDoc(window)
Is it really necessary? document object is just window.document.
Simpler:

Code: Select all

GetIePagePwb(param, value) {
   if !(param ~= "i)^(url|title)$")
      throw Exception("Pameter " . param . " not supported")
   (param = "url" && param := "LocationURL")
   for window in ComObjCreate("Shell.Application").Windows {
      WinGetClass, winClass, % "ahk_id" window.hwnd
      if (winClass != "IEFrame")
         continue
      try doc := window.document
      catch
         break
      obj := {LocationURL: window, title: doc}[param]
      if (obj[param] = value && found := true)
         break
   }
   if found
      Return window
}
Using:

Code: Select all

url := "https://www.google.com/"
Run, iexplore.exe %url%,,, PID
WinWait, ahk_pid %PID%

start := A_TickCount
while !(wb := GetIePagePwb("url", url)) && A_TickCount - start < 10000
   Sleep, 100

if !wb {
   MsgBox, Failed to get wb object by url
   Return
}
wb.Navigate("https://www.autohotkey.com/", navOpenInNewTab := 2048)
wb := ""

start := A_TickCount
while !(wb := GetIePagePwb("title", "AutoHotkey")) && A_TickCount - start < 10000
   Sleep, 100

if !wb {
   MsgBox, Failed to get wb object by title
   Return
}
wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click()

GetIePagePwb(param, value) {
   if !(param ~= "i)^(url|title)$")
      throw Exception("Pameter " . param . " not supported")
   (param = "url" && param := "LocationURL")
   for window in ComObjCreate("Shell.Application").Windows {
      WinGetClass, winClass, % "ahk_id" window.hwnd
      if (winClass != "IEFrame")
         continue
      try doc := window.document
      catch
         break
      obj := {LocationURL: window, title: doc}[param]
      if (obj[param] = value && found := true)
         break
   }
   if found
      Return window
}
Toni Osuna
Posts: 5
Joined: 18 Jul 2019, 19:36

Re: Click on specific button of existing web page.

22 Jul 2019, 17:11

Thanks all for your answers,

teadrinker the last code you sent works fine (Click in the button) but also creates another instance of the browser, I tried to eliminate this part of the script but then the "click" action does not work any more. (I am a VBA programmer not an expert in AHK, sorry my lack of skill).

See, this is my web page:

https://imgur.com/a/QhXDI7f

The objetive is make click on that button, labeled with "Run Test", and as a Test is run to each item, it is necessary to enter the Serial Number first and then click on "Run Test" button that is why the script must work on an existing page.

Also, in this part of the script:

Code: Select all

wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click()
How does the "mbr-buttons__btn" sentence to refer to the Forums button.

Thank you so much for your help, really appreciate it. :beer:
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

22 Jul 2019, 18:55

Toni Osuna wrote: How does the "mbr-buttons__btn" sentence to refer to the Forums button.
Image
Toni Osuna wrote: The objetive is make click on that button, labeled with "Run Test"
Unfortunately I can't help you with your button since I need the page html code. I may give you other example with any page, where I can see html.
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Click on specific button of existing web page.

23 Jul 2019, 10:16

teadrinker wrote:
22 Jul 2019, 14:33
Is it really necessary
you are almost right but 2 things you are not aware of it seems.
  • in your example window is actually a pwb not a DOM window
  • It is sometimes necessary to query the document object to avoid certain permission problems
While it is true that pwb.document returns The HTMLDocument coclass, which is functionally equivalent to the Dynamic HTML (DHTML) document object used in HTML script. it is not safe to assume that accessing DOM Document is the same as when you QueryInterface for it.

Hope this clarifies
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Click on specific button of existing web page.

23 Jul 2019, 10:32

Toni Osuna wrote:
22 Jul 2019, 17:11
The objetive is make click on that button, labeled with "Run Test"
There are many forms a button can take on a web page
  1. <button>Run Test</button>
  2. <input type="{button|submit|reset}" value="Run Test" />
Based on your image the 2 examples above seem most likely. Either way it now seems fortunate that i provided the library. You could simply

Code: Select all

#Include, iWebBrowser2.ahk
$ := new iWebBrowser2
pwb:= $.oIE_get()
$.FindbyText(pwb, "Run Test").click()
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
Toni Osuna
Posts: 5
Joined: 18 Jul 2019, 19:36

Re: Click on specific button of existing web page.

24 Jul 2019, 12:32

Thank you for your response tank and teadrinker.

I use the code teadrinker wrote:

Code: Select all

url := "https www.google.com /"  Broken Link for safety
Run, iexplore.exe %url%,,, PID
WinWait, ahk_pid %PID%

start := A_TickCount
while !(wb := GetIePagePwb("url", url)) && A_TickCount - start < 10000
   Sleep, 100

if !wb {
   MsgBox, Failed to get wb object by url
   Return
}
wb.Navigate("https://www.autohotkey.com/", navOpenInNewTab := 2048)
wb := ""

start := A_TickCount
while !(wb := GetIePagePwb("title", "AutoHotkey")) && A_TickCount - start < 10000
   Sleep, 100

if !wb {
   MsgBox, Failed to get wb object by title
   Return
}
wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click()				;Autohotkey forums button (searched by Class)
;wb.document.getElementById("MainContent_btnRetrieveTestData").(1).Click()		;My web page (searched by Id)


GetIePagePwb(param, value) {
   if !(param ~= "i)^(url|title)$")
      throw Exception("Pameter " . param . " not supported")
   (param = "url" && param := "LocationURL")
   for window in ComObjCreate("Shell.Application").Windows {
      WinGetClass, winClass, % "ahk_id" window.hwnd
      if (winClass != "IEFrame")
         continue
      try doc := window.document
      catch
         break
      obj := {LocationURL: window, title: doc}[param]
      if (obj[param] = value && found := true)
         break
   }
   if found
      Return window
}
In the line where the script looking for the Foroums button, the script search by Class, but my button (Run Test) does not have class, so I change the search by ID, but does not works.
This is the html code of the button: https://imgur.com/a/DHDhiVL
Image

Is there any other way that the search is not by class, could be by name or ID.

PD. This script fulfills its mission but also creates another instance of the same browser, there is any possibility to avoid this??

And thank you so much guys for your help..
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

25 Jul 2019, 19:01

tank wrote: in your example window is actually a pwb
@tank, thanks for your answer. But not all things are clear.
First, the question was just about pwb:
Toni Osuna wrote: I do not know how to create the Pwb object with an existing Web page.
Second, your link leads to nowhere:

Image

Third, it seems to me, my window and yours are the same since they are obtained by the same method:
tank wrote:

Code: Select all

        for window,k in ComObjCreate("Shell.Application").Windows
            if ( "Internet Explorer" = window.Name)
               {
               ...
               if ( possiblematch )
                  {
                  ...
                  oIE := window
                  }
               ...
               }
            ...
            return oIE
Is there a way to see the difference between my window and yours?

Toni Osuna wrote: I change the search by ID, but does not works.
I need to see your code to say what could be wrong.
Toni Osuna wrote: This is the html code of the button: https://imgur.com/a/DHDhiVL
I would click it like this:

Code: Select all

wb.document.getElementById("MainContent_btnRetrieveTestData").click()
Toni Osuna wrote: Is there any other way that the search is not by class, could be by name or ID.
Yes, there is querySelector and getElementById.
Toni Osuna wrote: This script fulfills its mission but also creates another instance of the same browser, there is any possibility to avoid this??
I need to see your code. :)
malcev
Posts: 865
Joined: 12 Aug 2014, 12:37

Re: Click on specific button of existing web page.

26 Jul 2019, 06:44

As I understand tank uses WbGet(), and You use IeGet() function.
https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
The right link about pwb is:
https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752127(v%3Dvs.85)
I do not know about what permission problems told tank, may be he gives example, but there may be some problems with IeGet() and tabs.
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=36660
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

26 Jul 2019, 08:54

malcev wrote: As I understand tank uses WbGet()
I thought, @tank meant the code he provided in this topic, this code uses IeGet()-like algorithm.
tank wrote:

Code: Select all

ie := new iWebBrowser2
pwb := ie.oIE_get() ;; current IE
malcev
Posts: 865
Joined: 12 Aug 2014, 12:37

Re: Click on specific button of existing web page.

26 Jul 2019, 11:35

Code: Select all

pwb := ie.oIE_get() ;; current IE
queries to this function:

Code: Select all

    IHTMLWindow2_from_IWebDOCUMENT( IWebDOCUMENT )
        {
        static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"  ; IID_IHTMLWindow2
        return ComObj(9,ComObjQuery( IWebDOCUMENT, IID_IHTMLWindow2, IID_IHTMLWindow2),1)
        }
as it done in WbGet().
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

26 Jul 2019, 12:10

malcev wrote: queries to this function:
It queries to this function to get pdoc:
pdoc := this.pDoc(window)
But then oIE (= window) is returned.
malcev
Posts: 865
Joined: 12 Aug 2014, 12:37

Re: Click on specific button of existing web page.

26 Jul 2019, 12:41

It queries to this function to get pdoc may be because of:
It is sometimes necessary to query the document object to avoid certain permission problems
But I have not encountered such situations.
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

26 Jul 2019, 13:08

We will wait for clarification from @tank. :)
Toni Osuna
Posts: 5
Joined: 18 Jul 2019, 19:36

Re: Click on specific button of existing web page.

26 Jul 2019, 17:47

teadrinker:

this code works fine BUT it creates another instance of Internet Explorer every time it runs:

Code: Select all

Pwb:= ComObjCreate( "InternetExplorer.Application" )													; Creates the ComObj
Pwb.Navigate("www.AutoHotkey.com")																		; Navigates to AutoHotkey.com
Pwb.Visible:= True																						; Shows the IE app

While ( Pwb.Busy || Pwb.ReadyState != 4 )																; Waits for the webpage to finish loading
	Sleep 10																							;	|

value := ""																								; Creates the variable ( not needed )

While ( value <> "Forums" )																				; Loops through the elements, until its innerText matches.
	value := Pwb.document.getElementsByTagName( "a")[ A_Index - 1].innerText, index := A_Index -1		; Gets the value, and stores the Index

Pwb.document.getElementsByTagName( "a")[ index].Click()													; Clicks on the Community Forum link.
This happens because the first line creates an instance of internet explorer and calls that object Pwb, what I need is to create the Pwb object of an active browser, so the search will be in this browser.

Also this script search by TagName, there is any way the script search by ID. According to the html code of my page:

Image https://imgur.com/a/DHDhiVL

The ID of my button is: "MainContent_btnRetrieveTestData". But I can't test this code because I can figure out how to do the Pwb thing.
teadrinker
Posts: 2183
Joined: 29 Mar 2015, 09:41
Contact:

Re: Click on specific button of existing web page.

26 Jul 2019, 18:02

Code: Select all

url := "http://myurl.com"  ; specify url of opened page

wb := GetIePagePwb("url", url)
if !IsObject(wb)
   throw Exception("Failed to get web browser object")
button := wb.document.getElementById("MainContent_btnRetrieveTestData")
if !IsObject(button)
   throw Exception("Failed to get button element")
button.click()
Return

GetIePagePwb(param, value) {
   if !(param ~= "i)^(url|title)$")
      throw Exception("Pameter " . param . " not supported")
   (param = "url" && param := "LocationURL")
   for window in ComObjCreate("Shell.Application").Windows {
      WinGetClass, winClass, % "ahk_id" window.hwnd
      if (winClass != "IEFrame")
         continue
      try doc := window.document
      catch
         break
      obj := {LocationURL: window, title: doc}[param]
      if (obj[param] = value && found := true)
         break
   }
   if found
      Return window
}
Edited.
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Click on specific button of existing web page.

26 Jul 2019, 18:43

teadrinker wrote:
26 Jul 2019, 13:08
clarification
for what exactly I posted working code solutions. I am unsure why we aren't trying them
teadrinker wrote:
26 Jul 2019, 12:10
pdoc := this.pDoc(window)
But then oIE (= window) is returned.
No it returns the parentwindow property of document object I explained this already
malcev wrote:
26 Jul 2019, 12:41
such situations.
frames
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], FonBass, Google [Bot] and 52 guests