How can I execute this code?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

How can I execute this code?

07 Jul 2016, 11:14

The following code is from an internal tool at work. I'm looking to automate some tasks and the application we use is a web application. I haven't used AutoHotKey in a few years and looking for a little help on getting started again.

Code: Select all

<a class="dellmetrics-quotemenu ng-isolate-scope" id="quoteDetail_copyquote" data-c-id="quoteDetail_copyquote" data-testid="quoteDetail_copyquote" data-ng-click="copyQuote()" data-ng-disabled="copyQuoteDisabled()" data-resource-ids="customerBaseIdsArray" data-show-if-permission="urn:DSA:GenericPermission:Quote:Update" ensighten-activation-event="copyquote" c-ensighten-activation-event="">
Copy Quote</a>
How can I get the above code to execute from a script? I'm basically looking for a way to have the "Copy Quote" link clicked for me.
ameyrick
Posts: 122
Joined: 20 Apr 2014, 18:12

Re: How can I execute this code?

07 Jul 2016, 13:15

https://autohotkey.com/board/topic/4705 ... -tutorial/

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.visible := true
wb.Navigate("work application webpage")

while wb.readyState != 4 or wb.busy
	Sleep, 10

wb.document.getElementByID("quoteDetail_copyquote").click()
Last edited by ameyrick on 07 Jul 2016, 14:50, edited 1 time in total.
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 14:00

I tried the following and it was a no go.

Code: Select all

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.Navigate("work application webpage")
 
wb.getElementByID("quoteDetail_copyquote").click()
exitapp
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 14:14

ameyrick wrote:This guide might help
https://autohotkey.com/board/topic/6456 ... -webpages/
Yeah I tried using that but I've done something wrong I think.
Guest

Re: How can I execute this code?

07 Jul 2016, 14:27

Try

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("www.google.com")
;<---instead of google(as defined above), fill with URL of "work application webpage"--->
IEWait(wb)
wb.getElementByID("quoteDetail_copyquote").click()
return
 
IEWait(wb){
   while wb.busy || (wb.document && wb.document.readyState != "complete") || wb.readyState!=4
   	Sleep 10
}
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 14:35

Guest wrote:Try

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("www.google.com")
;<---instead of google(as defined above), fill with URL of "work application webpage"--->
IEWait(wb)
wb.getElementByID("quoteDetail_copyquote").click()
return
 
IEWait(wb){
   while wb.busy || (wb.document && wb.document.readyState != "complete") || wb.readyState!=4
   	Sleep 10
}

I really just need it to use the current open window as the URL will change a lot. But here is what I tried and I got an error with the WAIT code.

Code: Select all

---------------------------
test.ahk
---------------------------
Error:  0x800706B5 - The interface is unknown.


Specifically: busy

	Line#
	005: wb := ComObjCreate("InternetExplorer.Application")
	006: wb.Visible := True  
	007: wb.Navigate("http://outwebsite.com/quote/details/QuoteNumber/1013791480868")  
	009: IEWait(wb)  
	010: wb.getElementByID("quoteDetail_copyquote").click()  
	011: Return
	013: {
--->	014: While,wb.busy || (wb.document && wb.document.readyState != "complete") || wb.readyState!=4
	015: Sleep,10
	016: }
	017: Exit
	018: Exit
	018: Exit

Continue running the script?
---------------------------
Yes   No   
---------------------------
ameyrick
Posts: 122
Joined: 20 Apr 2014, 18:12

Re: How can I execute this code?

07 Jul 2016, 14:45

Whats the page <title> of your web application?

Code: Select all

title := "My web app title"
;url := "http://192.168.0.1"

wb := IEGet(title) ;connects to open window by title 
/*
if !wb
	wb := ComObjCreate("InternetExplorer.Application") ; opens new window

wb.visible := true
wb.Navigate(url)
*/

while wb.readyState != 4
	Sleep, 10

wb.document.getElementByID("quoteDetail_copyquote").click()
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
}


Tiredness kills scripting ability, check that you are using:

wb.document.getElementByID("quoteDetail_copyquote").click()

As I made that error in my first example.



Also if you use this version of IEGet() it should connect you to the active tab when you don't provide a title

Code: Select all

wb := IEGet()

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
	; Below added for when no tab name/page title provided ~ ameyrick
	If InStr( wb.FullName, "iexplore.exe" ) 
		Return wb
} ;Original IEGet() written by Jethrow
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 15:44

Thanks to your help, here is some code that I have working so far.

Code: Select all

title := "Sales Application"
 
wb := IEGet(title) ;connects to open window by title 
 
wb.document.getElementByID("quoteDetail_copyquote").click()

while wb.readyState != 4
	Sleep, 10

wb.document.getElementByID("quoteCreate_changeCustomer").click()

wb.document.getElementByID("changeCustomer_confirm").click()
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
}
A problem I'm having is the script will not wait while the web application is processing the request.

Here is the busy code from the application

Code: Select all

    <!-- Busy Overlay -->
    <div data-ng-show="showBusyOverlay" data-c-id="busy-overlay" data-ng-cloak="" onclick="event.stopPropagation()"></div>

    <!-- Busy Indicator -->
    <div data-ng-show="showBusyIndicator" data-c-id="busy-indicator" data-ng-cloak="" onclick="event.stopPropagation()">
        <i aria-hidden="true" class="icon-ui-loading mg-btm-10" style=""></i>
        <p>Processing... Please Wait.</p>
    </div>
ameyrick
Posts: 122
Joined: 20 Apr 2014, 18:12

Re: How can I execute this code?

07 Jul 2016, 16:21

Can try to connect to the "busy-indicator" object events, maybe OnChange

something like this:

Code: Select all

title := "Sales Application"
 
wb := IEGet(title) ;connects to open window by title 
 
wb.document.getElementByID("quoteDetail_copyquote").click()
 
;while wb.readyState != 4
;	Sleep, 10

loading := true ;flag var

div_array := wb.document.getElementsByTagName("div")
;msgbox, % div_array.length
loop, % div_array.length
{
	;msgbox, % div_array[a_index-1].getattribute("data-c-id")
	if ( div_array[a_index-1].getattribute("data-c-id") = "busy-indicator" ){
		busy := div_array[a_index-1] ;store busy-indicator obj into busy var
		break ; exit loop
	}
}

ComObjConnect(busy, "busy_") ;connect to busy object events

;onChange event
busy_OnChange(){
	global 
	ComObjConnect(busy) ;disconnect busy object events
	loading := false ;flag var
}

while loading = true
	sleep, 10

wb.document.getElementByID("quoteCreate_changeCustomer").click()

Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 17:23

Doesn't seem to set the flag to false.
ameyrick
Posts: 122
Joined: 20 Apr 2014, 18:12

Re: How can I execute this code?

07 Jul 2016, 17:39

try connecting to the data-c-id="busy-overlay" instead
or play around with different events http://www.w3schools.com/tags/ref_eventattributes.asp

Code: Select all

div_array := wb.document.getElementsByTagName("div")
;msgbox, % div_array.length
loop, % div_array.length
{
	;msgbox, % div_array[a_index-1].getattribute("data-c-id")
	if ( div_array[a_index-1].getattribute("data-c-id") = "busy-overlay" ){
		busy := div_array[a_index-1] ;store busy-overlay obj into busy var
		break ; exit loop
	}
}


If events don't work, could try testing obj existence, assuming a javascript page rewrite

Code: Select all

While busy.getattribute("data-c-id") = "busy-overlay"
	sleep, 10
or

Code: Select all

Loop
{
	try x := busy.getattribute("data-c-id")
	catch
		break
	sleep, 10		
}
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 18:40

So from testing, everything get's stuck in a loop and won't exit.

This didn't seem to detect also. /head-to-desk

Code: Select all

While busy.getattribute("data-c-id") = "busy-overlay"
	sleep, 10
ameyrick
Posts: 122
Joined: 20 Apr 2014, 18:12

Re: How can I execute this code?

07 Jul 2016, 18:47

Crazyace wrote:So from testing, everything get's stuck in a loop and won't exit.

This didn't seem to detect also. /head-to-desk

Code: Select all

While busy.getattribute("data-c-id") = "busy-overlay"
	sleep, 10
Just to check. Which obj were you searching for:
if ( div_array[a_index-1].getattribute("data-c-id") = "busy-indicator" )
or
if ( div_array[a_index-1].getattribute("data-c-id") = "busy-overlay" )
Crazyace
Posts: 9
Joined: 22 Jan 2015, 15:22

Re: How can I execute this code?

07 Jul 2016, 19:19

I tried both with no luck.
Guest

Re: How can I execute this code?

08 Jul 2016, 12:34

Total guess...but...

Is your script ran as Admin?

Seems like I ran into a similar issue. In that, I could connect to the browser but as soon as a I submitted anything to the web server or was redirected, i would lose connection to the browser.

I think I finally resolved my issue by running as Admin and installing Java. Though, I'm not recommending installing Java and I'm not certain why it would even matter.

Return to “Ask for Help (v1)”

Who is online

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