RPAChallenge with AHK, COM, and JSWrapper.ahk

Post your working scripts, libraries and tools
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

07 Jul 2020, 18:26

If You want to test different browsers speed then You can do it with webdriver API:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69390
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

07 Jul 2020, 20:32

Thanks, @malcev. I can run the example you posted in that thread. But I downloaded the github repository for AHKWebDriver.ahk, and I can't get any of those examples to run.
But I probably misunderstood. Did you mean that I should use the WebDriver API itself rather than AHKWebDriver.ahk?
Regards,
burque505
AHKStudent
Posts: 891
Joined: 05 May 2018, 12:23

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

07 Jul 2020, 20:40

burque505 wrote:
07 Jul 2020, 18:07
This is just for reference, not for speed. Plain Vanilla AHK, 816ms. No artificial flavors, preservatives or sweeteners.

Code: Select all

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

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true  ; This is known to work incorrectly on IE7.
ie.Navigate("http://rpachallenge.com")
while (ie.Busy)
	sleep, 100

doc := ie.Document

doc.querySelector("button.waves-effect").click()

loop, %lastrow% {
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]
doc.querySelector("input[ng-reflect-name='labelEmail']").value := emailvar
doc.querySelector("input[ng-reflect-name='labelAddress']").value := addressvar
doc.querySelector("input[ng-reflect-name='labelFirstName']").value := fnvar
doc.querySelector("input[ng-reflect-name='labelLastName']").value := lnvar
doc.querySelector("input[ng-reflect-name='labelPhone']").value := phonevar
doc.querySelector("input[ng-reflect-name='labelRole']").value := rolevar
doc.querySelector("input[ng-reflect-name='labelCompanyName']").value := cnvar
doc.querySelector("input[value='Submit']").click()

} ; end loop


sleep, 5000
ie.quit()
After adding

SetBatchLines, -1

I used your code and it did it in 490ms
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

07 Jul 2020, 20:51

@AHKStudent, great tip. That got me down to 442ms on a Win10 machine, old but has 32GB RAM and an SSD hard disk, so it's not that slow.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 02:57

burque505, for me examples work.
I put AHKWebDriver.ahk and json.ahk to the folder of examples, run chromedriver and then run test_url.ahk.
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 06:41

@malcev, I didn't have that kind of luck. My files are exactly where you placed yours, but I get this error with test_url.ahk:

Code: Select all

Error in #include file <My File Path>:
     0x800C0005 - 
Source:		msxml3.dll
Description:	The system cannot locate the resource specified.


HelpFile:		(null)
HelpContext:	0

Specifically: Send

	Line#
	393: Return,""
	394: Return,this.rc.value
	395: }
	399: {
	401: rc := {}
	402: WS_SERVIDOR.Open(metodo,url, false)  
	403: WS_SERVIDOR.setRequestHeader("Content-Type","application/json; charset=UTF-8")  
--->	404: WS_SERVIDOR.Send(cuerpo)  
	405: rc.status  := WS_SERVIDOR.Status  
	406: rc.isError := (WS_SERVIDOR.Status < 200 || WS_SERVIDOR.Status > 299)  
	407: rc.raw     := WS_SERVIDOR.ResponseText  
	408: rc.value   := JSON.Parse(rc.raw).value  
	409: rc.sendRaw :=  cuerpo  
	410: Return,rc
	411: }
I'm using json.ahk from the repo; I'll try one from my file system now.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 08:40

I think it is chromedriver error.
You have to download and run version of chromedriver that is needed for Your browser version.
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 10:19

I don't think that's it. I'm using the same version (for Chrome 83) that I use for SeleniumBasic and all my Python-based scripts. They all work.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 15:13

Try like this:

Code: Select all

wd := new WDSession("http://127.0.0.1:4444/")
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

08 Jul 2020, 15:21

Thanks, that works! Here's the whole script case it helps someone else.

Code: Select all

;#noenv
#include AHKWebDriver.ahk
#include json.ahk

Run, %A_ScriptDir%\geckodriver.exe 
		
wd := new WDSession("http://127.0.0.1:4444/")
if(wd.rc.isError){
    msgbox % "Error:" wd.rc.value.error " " wd.rc.value.message
    ExitApp
}
wd.url("https://autohotkey.com")
wd.debug()
; next force error
wd.url("ixbxm.com")
wd.debug()
wd.delete
Unless I run the driver first it fails. This is the code in the example:
Spoiler
I appreciate the help, @malcev! :D

EDIT: Can't get Chrome to work yet, though. Trying to work my way through this post.. It appears that since version 63 you can't specify the remote debugging port as an argument, just as an option.

Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 16:15

If You look at the end of AHKWebDriver.ahk You will see how to set debugging port in Chrome.
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 17:38

Thanks, I assume you mean this, which I have seen. However, I don't know whether i have to incorporate this JSON into a script, or how to call it if I do, or whether I have to modify AHKWebDriver.ahk.
Spoiler
I can retrieve the needed information, I think:

Code: Select all

ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/[email protected]{#416})
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 18:08

You just have to send it.
For example open window 1000x800 json can be like this:

Code: Select all

options = {"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"args":["window-size=1000,800"]}}}}
wd := new WDSession(, options)
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 18:54

Thank you for your efforts to help me, but I'm still completely lost. The code you provided has no context I can work from other than it's right before wd := new WDSession(, options).
By the time the script reaches that, chromedriver is already executing and has randomly selected a port to listen to.
I need to get the option information to chrome somehow.

A script that works, with no code left out, would be extremely helpful.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 19:04

I do not understand what do You want.
You asked:
It appears that since version 63 you can't specify the remote debugging port as an argument, just as an option
I wrote examle how to send options with json.
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 19:18

I would like to have a working script using Chrome and AHKWebDriver.ahk.
Code you provided did not work for me with Chrome, I get the same errors as before.
Thanks anyway.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 19:22

If You need to change port in options, You have to change json like this.

Code: Select all

options = {"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"args":["remote-debugging-port=9222"]}}}}
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

09 Jul 2020, 20:41

Same results, I'm giving up on AHKWebDriver.ahk, thanks for your efforts.
Perhaps one day someone will post a working script using Chrome.
Regards,
burque505
malcev
Posts: 657
Joined: 12 Aug 2014, 12:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

11 Jul 2020, 16:06

For me it works without setting options.
If I run chromedriver on specific port like this

Code: Select all

C:\temp\chromedriver.exe --port=1234
Then I can connect with this code

Code: Select all

wd := new WDSession("http://127.0.0.1:1234/")
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: RPAChallenge with AHK, COM, and JSWrapper.ahk

11 Jul 2020, 16:25

No luck.
Capture.PNG
Capture.PNG (17.04 KiB) Viewed 1024 times
Capture2.PNG
Capture2.PNG (17.01 KiB) Viewed 1024 times
I don't see how that could possibly work.

Code: Select all

#include AHKWebDriver.ahk
#include json.ahk
Run, %A_ScriptDir%\chromedriver.exe --port=1234
wd := new WDSession("http://127.0.0.1:1234/")
if(wd.rc.isError){
    msgbox % "Error:" wd.rc.value.error " " wd.rc.value.message
    ExitApp
}
wd.url("https://autohotkey.com/")
wd.debug()
; next force error
wd.url("ixbxm.com")
wd.debug()
wd.delete

Return to “Scripts and Functions”

Who is online

Users browsing this forum: TheArkive and 17 guests