This wrapper can pass variables back and forth between AHK and JS. See the example at the link above.
Here's the code for the challenge (quick and dirty, sorry about that).
Code: Select all
#Include JSWrapper.ahk
; THANKS to Fade who got almost no response to this great JS wrapper that I can see.
; Get the wrapper here:
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=47716&p=213972
; (April 24, 2018 post)
; burque505, July 5, 2020
OnExit("Cleanup")
; Get the challenge file
URLDownloadToFile, http://rpachallenge.com/assets/downloadFiles/challenge.xlsx, challenge.xlsx
; Create arrays for each Excel column
firstNameArray := []
lastNameArray := []
companyNameArray := []
roleArray := []
addressArray := []
emailArray := []
phoneArray := []
lastrow := 0 ; Used later
path := A_ScriptDir
xl := ComObjCreate("Excel.Application")
xl.Visible := true
xl.Workbooks.Open(path . "\challenge.xlsx")
;loop to fill the arrays
while (Xl.Range("A" . A_Index).Value != "") {
indexer := A_Index -1
firstNameArray[indexer] := Xl.Range("A" . A_Index).Value
lastNameArray[indexer] := Xl.Range("B" . A_Index).Value
companyNameArray[indexer] := Xl.Range("C" . A_Index).Value
roleArray[indexer] := Xl.Range("D" . A_Index).Value
addressArray[indexer] := Xl.Range("E" . A_Index).Value
emailArray[indexer] := Xl.Range("F" . A_Index).Value
phoneArray[indexer] := Xl.Range("G" . A_Index).Value
lastrow := A_Index -1
}
; Don't need Excel anymore.
xl.Quit
; Start of of JSWrapper example code. See the link above for more information.
hmOleAut32 := DllCall("LoadLibrary", "Str", "OleAut32.dll", "Ptr")
ie := ComObjCreate("InternetExplorer.Application")
; Go to challenge website
ie.Navigate("http://rpachallenge.com")
ie.Visible := true
while (ie.ReadyState != 4)
Sleep 10
window := new JSWrapper(ie.document.parentWindow)
jsStart =
(
window.moveTo(0, 0);
window.resizeTo(screen.availWidth, screen.availHeight);
start = document.querySelector('button.waves-effect');
start.click();
)
; Click the 'Start' Button
window.eval(jsStart)
; Do the challenge
loop, %lastrow% { ; start loop
fnvar = % firstNameArray[A_Index]
lnvar = % lastNameArray[A_Index]
cnvar = % companyNameArray[A_Index]
rolevar = % roleArray[A_Index]
addressvar = % addressArray[A_Index]
emailvar = % emailArray[A_Index]
phonevar = % phoneArray[A_Index]
window["firstName"] := fnvar
window["lastName"] := lnvar
window["companyName"] := cnvar
window["role"] := rolevar
window["address"] := addressvar
window["email"] := emailvar
window["phone"] := phonevar
; The variables change value each time through the loop
js =
(
m = document.querySelector('input[ng-reflect-name="labelEmail"]');
m.value = email;
a = document.querySelector('input[ng-reflect-name="labelAddress"]');
a.value = address;
f = document.querySelector('input[ng-reflect-name="labelFirstName"]');
f.value = firstName;
l = document.querySelector('input[ng-reflect-name="labelLastName"]');
l.value = lastName;
p = document.querySelector('input[ng-reflect-name="labelPhone"]');
p.value = phone;
r = document.querySelector('input[ng-reflect-name="labelRole"]');
r.value = role;
c = document.querySelector('input[ng-reflect-name="labelCompanyName"]');
c.value = companyName;
s = document.querySelector('input[value="Submit"]');
s.click();
)
window.eval(js)
} ;end loop
DllCall("FreeLibrary", "Ptr", hmOleAut32)
Escape::
if (WinExist("ahk_exe iexplore.exe"))
ie.Quit()
DllCall("FreeLibrary", "Ptr", hmOleAut32)
ExitApp
; You can figure out a better exit strategy, I'm sure.
Cleanup() {
global
if (WinExist("ahk_exe iexplore.exe"))
ie.Quit()
DllCall("FreeLibrary", "Ptr", hmOleAut32)
}
Regards,
burque505