1
votes

I've been fooling around with trying to get a script working to automate button pressing. Not an easy task for a complete novice, I can assure you.

Here is the html code for said button:

<div class"rightButtonSection">
<button name="PierPropertiesContainer_componentnext_0" title="Next Page" class="button buttonLink" onclick"setKeys(event);__xee72onclick(this);" type="button">Next</button>
</div>

This is embedded quite deep in the code, inside a specific frame (I think that's the right term).

this link provided in another thread contains the script I need, but in my circumstance I am having trouble implementing it.

I got as far as this with my attempt:

+q::

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
}

wb := IEGet("Webtop - Internet Explorer")
wb.Visible := true
wb.document.getElementByID("button").click() ;// is button the ID? try the name or a different selector

return

Upon running the code, I get this in the... script...running...viewing..window thing:

001: Return (19.94)
004: if name = 
004: WinGetTitle,name,ahk_class IEFrame
005: name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
006: For wb, in ComObjCreate("Shell.Application").Windows() (0.11)
007: if wb.LocationName=Name &&  InStr(wb.FullName, "iexplore.exe")  
007: if wb.LocationName=Name &&  InStr(wb.FullName, "iexplore.exe")  
009: } (3.21)

If I'm understanding this correctly, which I doubt, it seems to have captured my two running instances of IE, but that is as far as it gets with the endeavour.

HOWEVER! I just discovered the 'Variables and their contents' option in the view dropdown of the script viewing window, and it reads:

0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
wb[0 of 0]:  

That is a bit concerning, sort of implies that it hasn't found anything to put into wb at all.

I'm not sure how to copy the contents of windowspy, but the topmost title window box reads:

Webtop - Internet Explorer
ahk_class IEFrame
ahk_exe iexplore.exe

I think the elementID is actually "button", but this is also the tagname, the button name="PierPropertiesContainer_componentnext_0" which I have tried, I've tried changing this as getElementByName, I've tried a number of permutations.

I have a feeling because some of the unknown restrictions on the system I'm using at work are effecting a step in the first portion of the code, but as of this moment, I'm stuck for ideas. Out of my depth to say the least!

I saw in some thread I may have to try creating a loop to cycle through elements to find the one you want but...

Any help on the next step would be great!!

Cheers

Edit1: The site in question is an Oracle database with a documentum front end, and a web based user interface. It's running on the intranet at work, and seems to be inaccessible to the wider internet without being connected to the network.

Edit2: I have tried more messing around with the code. I think my initial problem was that I had the Function in the wrong place; once it hit "Return wb" the script would end. With the meat of the script up front and the Function at the end of the script, it at least runs the whole script!

The "ReadyState =! 4" segment looped forever, so I removed this and left it as while wb.busy, which seems to run everytime.

Still no clicking though. So now I am wondering if there is anything else I can do with this getElement business to test that it is working. I've seen focus() mentioned, and I have tried that with similarly negative results. I'm guessing this is like tab focus?

I tried the button[5] method with different numbers, but sadly that was also ineffective.

My instincts tell me wb.document.getElementByName is the way to go, as the code reads "

Edit 3: Here is the current state of my code (that "reload" is coming in handy as well):

+q::

wb := IEGet("Webtop")  ;// call to IEGet function passing the IE tab name as a parameter to assign the tab to a wb object
wb.Visible := true
while wb.busy or wb.ReadyState != 4  ;// make sure page is fully loaded
   Sleep 150
document.getElementsByTagName("button")[1].focus()
;// is "button" the ID? No. Try the name, or use a different selector
return

IEGet(name="") {  ;//IEGet is a function. It returns a wb object
   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")
         {
         ;MsgBox % "Found it! (" . wb.FullName . ")"  ;  for debugging (comment out when done)
         return wb
         }
}

f6::
reload
return

Edit 4

I've all but given up selecting the element I am after at this point. It seems because the site is running some JAVA business beyond my feeble comprehension, the button doesn't exist on the surface level, so AHK can't see it.

The solution I have got is to focus on the one element AHK can see (the title) and then hit shift+tab a number of times till I get to the buttons I want to press.

The fatal flaw here is that if any change occurs to move the tab/button position, it won't work. So it's a bit temperamental to say the least. I put in a pixel colour check in the vain hope that that pixel position stays consistent across everyone's UI, just to have some sort of failsafe in place to stop the automation going on a wild killing spree.

f6::

wb := IEGet("Webtop")  ;// call to IEGet function passing the IE tab name as a parameter to assign the tab to a wb object
wb.Visible := true
while wb.busy ;or wb.ReadyState != 4  ;// make sure page is fully loaded
   Sleep 150

loop 4
{
    PixelGetColor, color, 145,145
    ;msgbox %color%
    if color <> 0x9D663B
        break

    wb.Document.all(1).focus()

    if A_index = 4 
        {
        send +{tab 7}
        send {enter}
        break
        }

    send +{tab 5}
    send {enter}
    while wb.busy
        sleep 150
}
return

IEGet(name="") {  ;//IEGet is a function. It returns a wb object
   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")
         {
         ;MsgBox % "Found it! (" . wb.FullName . ")"  ;for debugging (comment out when done)
         return wb
         }
}
1
Whoops, first thing is you are still using IEGet wrong. IEGet returns your wb. I will put that in an answer, and let us know if the rest is good . . . - PGilm

1 Answers

1
votes

Per my comment, to start with, here is how to use the IEGet:

+q::

IEGet(name="") {  ;//IEGet is a function. It returns a wb object
   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")
         {
         MsgBox % "Found it! (" . wb.FullName . ")"  ;  for debugging (comment out when done)
         return wb
         }
}

wb := IEGet("Webtop")  ;// call to IEGet function passing the IE tab name as a parameter to assign the tab to a wb object
wb.Visible := true
while wb.busy or wb.ReadyState != 4  ;// make sure page is fully loaded
   Sleep 150
MsgBox % wb.document.getElementByID("PierPropertiesContainer_componentnext_0").innerHTML ;// or innertext or outerHTML
wb.document.getElementByID("PierPropertiesContainer_componentnext_0").click() ;// is "button" the ID? No. Try the name, or use a different selector

return

Note, I added a little routine to make sure the IE page is done loading (it should be, right, it's in an open tab, but just in case).

If you need the "button" you need the "TagName" selector and an [enumeration]:

wb.document.getElementsByTagName("button")[3].click()  ;// what number button is it?

EDIT: added a msgbox in IEGet to help diagnose what is going wrong for OP

Please let us know how you get along with it . . .