0

I am developing an AHK script for my company to automate some tedious manual processing on an Internet Explorer interface. So far I have been able to create an instance of IE, detect if it exists/is active, and I've been able to "getElementById" to fill in text fields, set focus, retrieves values and click on buttons.

But for the very last step, I can't for the life of me figure it out: there are a few links on this interface, which are not simple URL hyperlinks that lead to another page. "Inspecting the element" on one of these shows this HTML code:

<span class="relatedLink" id="a_statusChangeLink" style="color: blue;" onclick="javascript:openWindowL('StatusChange.aspx?Co=ABC&Cov=001&Ident=AAAAA&Digest=0obCAhixDLtLZRc10og9fNmgf0F&PhzKUudf2spZF14')">Change Status</span>

There are a few of these links side by side, I have been able to "getElementsByClass" using that "relatedLink" class, and match which one had .innerText = "Change Status". Index is 9 in the array of links in this class. My Issue? The .Click() property is NOT working. As you can see from the HTML snippet, it triggers a JS function that opens another window. I tried just "Navigating" to the onclick link, but the "Digest" argument is a key that changes every single time. Also FYI, these links only appear on the page once a button is clicked; they're not there before.

I tried this: AutoHotKey JavaScript Link But it still comes down to just sending a Click, and that doesn't do anything :/. I've tried sending multiple clicks too, to no avail.

Thank you so much for any advice you can provide :).

My relevant code:

IELoad(myWB)
{
    If !myWB
        Return False
    Loop
        Sleep, 50
    Until (myWb.Busy)
    Loop
        Sleep, 100
    Until (!myWB.Busy)
    Loop
        Sleep, 500
    Until (myWB.Document.Readystate = "Complete")
}
^t::    
    myWB := ComObjCreate("InternetExplorer.Application")
    myWB.Visible := True
    myWB.Navigate("http://blabla.domain.local/blah.aspx")
    IELoad(myWB)
    MsgBox, 64, Loaded, Loaded!
    If WinActive("ahk_class IEFrame") > 0
    {
        SetTitleMatchMode, 2
        WinGetActiveTitle, myTitle
            if InStr(myTitle, "Blah") > 0
            {
                ;MAIN CODE HERE
                myWB.document.getElementById("a_TransactionButton").Click()
                IELoad(myWB)
                Sleep, 500

                ;Now the links appear - We want id=a_statusChangeLink

                While (myVal <> "Change Status")
                    myVal:= myWB.document.getElementsByClassName("relatedLink")[A_Index].innerText, index := A_Index
                MsgBox, 64, Test, Count is: %myVal% and index is: %index%
                myWB.document.getElementsByClassName("relatedLink")[index].Click()

                ;This is an alternative way of getting that element

                links := myWB.document.getElementsByClassName("relatedLink")
                Loop, % links.length
                    n := A_Index - 1
                Until, links[n].innerText = "Change Status"
                links.item(n).click()

                ExitApp         
            }else
            {
                MsgBox, 64, Window not found, I did not detect an active Blah window...
                ExitApp
            }
    }
    MsgBox, 64, IE Not Found, I did not detect an active IE window...
    ExitApp
return

Esc::ExitApp
wyzo
  • 1
  • 2
  • TL;DR... please, edit your question adding only what is the exact problem you are facing and what is the desired result. Also, please include the code that is useful for us to debug if it is a code problem/error – Calvin Nunes Aug 17 '18 at 17:41
  • Ok done - tried to be specific with what I've tried so far. And added the code. Thank you! – wyzo Aug 17 '18 at 18:15

0 Answers0