AutoHotKey automation with Chrome Java Issue Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Moubasher
Posts: 2
Joined: 22 May 2022, 17:48

AutoHotKey automation with Chrome Java Issue

Post by Moubasher » 22 May 2022, 18:31

Hello valued members,

I am having an issue with the automation of some AutoHotKey and Chrome automation using the Chrome.ahk.

The issue is I am trying to automatically log-in to some websites using ahk Chrome integration and java, each section is excuted and goes to the next one, if I have more than 6 sections I always receive the error message which I think Java error :

Code: Select all

Script Error
An error has occurred in the script on this page.
Line: 1
Char: 1
Error: SecurityError
Code: 0
URL:
Do you want to continue running scripts on this page?
Yes   No
If I move the section to a new ahk file and call the second file from the first one, the code continues without issues.

What could be the problem please and is there is anything can be improved in my code

below are part of my code but basically all the sections are like this

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SetTitleMatchMode, 2
SetBatchLines, -1
#SingleInstance, force
;#HotkeyModifierTimeout 100
#Include, Chrome.ahk ;https://github.com/G33kDude/Chrome.ahk/releases
#Persistent

; Asks for the Password since most webssites uses Single Sign On
InputBox, DomUser, Enter Domain User, Enter Domain Uername,,200, 130,,,,,
InputBox, DomPass, Enter Domain Password, Enter Domain Password, hide,200, 130,,,,,

;***********************************
; The main Script File 1
; ************ Start ***************

; Run Chrome with Remote Debugging
run, chrome.exe --remote-debugging-port=9222

if !FileExist("profile")
	FileCreateDir, % "profile"


;***********************************
; Section 1
; Cisco Manager 1
;************ Start ****************
page := Chrome.GetPageByTitle("Unified Computing System")
if !IsObject(page) {
	chrome := new chrome("profile", "https://link.local")
	sleep 6000
	gosub, UCSMain1
}

UCSMain1:
	page := Chrome.GetPageByTitle("Unified Computing System")
if IsObject(page) {

	SetKeyDelay, 50
	page := Chrome.GetPageByTitle("Unified Computing System")
	page.WaitForLoad("complete")
	page.Evaluate("document.querySelector('#dijit_form_TextBox_0').value = '" DomUser "'")
	page.Evaluate("document.querySelector('#dijit_form_TextBox_1').value = '" DomPass "'")
	page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > div.dijitReset.dijitInputField.dijitButtonText > span').textContent = 'comapny'")
	page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > input[type=hidden]').value='company'")
	page.evaluate("document.querySelector('#xwt_widget_form_DropDown_0').ariaValueNow ='company'")
	sleep 1000
	WinActivate, Unified Computing System,,,
	send, {Tab 2}{Down 3}{Enter}{Tab}{Enter}
	;~ sleep 1000
	;~ send, {Tab}
	;page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > div.dijitReset.dijitInputField.dijitButtonText > span').outerText = 'company'")
	;page.Evaluate("document.querySelector('#loginContainer_loginSubmit_label').click()")
}

;***********************************
; Section 2
; Cisco UCS Manager 2
;************ Start ****************
UCS2Main:
page := Chrome.GetPageByURL("https://link.local")
if !IsObject(page) {
	chrome := new chrome("profile", "https://link.local")
	sleep 6000
}

	page := Chrome.GetPageByURL("https://link.local")
if IsObject(page) {
	SetKeyDelay, 50
	page := Chrome.GetPageByURL("https://link.local")
	page.WaitForLoad("complete")
	page.Evaluate("document.querySelector('#dijit_form_TextBox_0').value = '" DomUser "'")
	page.Evaluate("document.querySelector('#dijit_form_TextBox_1').value = '" DomPass "'")
	page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > div.dijitReset.dijitInputField.dijitButtonText > span').textContent = 'company'")
	page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > input[type=hidden]').value='company'")
	page.evaluate("document.querySelector('#xwt_widget_form_DropDown_0').ariaValueNow ='company'")
	sleep 1000
	;WinActivate, Unified Computing System,,,
	send, {Tab 2}{Down 3}{Enter}{Tab}{Enter}
	;goto, DataDomainMain
	;~ sleep 1000
	;~ send, {Tab}
	;page.Evaluate("document.querySelector('#xwt_widget_form_DropDown_0 > tbody > tr > td.dijitReset.dijitStretch.dijitButtonContents > div.dijitReset.dijitInputField.dijitButtonText > span').outerText = 'company'")
	;page.Evaluate("document.querySelector('#loginContainer_loginSubmit_label').click()")

}


;***********************************
; Section 3
;     Dashbored 
; ************ Start ***************

	Dashboard:
	page := Chrome.GetPageByTitle("Integration Dashboard")
if !IsObject(page) {
	chrome := new chrome("profile", "http://link.com")
	sleep 100
	chrome := new chrome("profile", "http://link.com")
	sleep 100
	chrome := new chrome("profile", "http://link.com")
	sleep 100
	chrome := new chrome("profile", "http://link.com")
	sleep 2000
}


;***********************************
; Section 4
;     Data Domain
; ************ Start ***************

page := Chrome.GetPageByTitle("Data Domain")
if !IsObject(page) {
	chrome := new chrome("profile", "https://link.local")
	sleep 3000
	Gosub, DataDomain
}

DataDomain:
page := Chrome.GetPageByTitle("Data Domain")
page.WaitForLoad("complete")
; here I am querying the Input box by TagName instead of Selector because the ID keeps changing all the time, tag name is the tag like <input...>
; in the ('input')[2], number 2 indicates the index of the input if it is the username input box or the password input box,
; All this can be verified in the Chrome debug tool
page.Evaluate("document.getElementsByTagName('input')[2].value='username'")
page.Evaluate("document.getElementsByTagName('input')[3].value='password'")
;Click the Log IN Button
page.Evaluate("document.querySelector('#login-button').disabled = false")
page.Evaluate("document.querySelector('#login-button').click()")

run, Script2.ahk

ExitApp

gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: AutoHotKey automation with Chrome Java Issue  Topic is solved

Post by gregster » 22 May 2022, 21:09

Moubasher wrote:
22 May 2022, 18:31
if I have more than 6 sections I always receive the error message
See viewtopic.php?f=6&t=42890&p=358760#p358760

Moubasher
Posts: 2
Joined: 22 May 2022, 17:48

Re: AutoHotKey automation with Chrome Java Issue

Post by Moubasher » 23 May 2022, 08:53

gregster, Thank you very much for your help, really appreciate, now I can run all the sections in one file :superhappy:

Post Reply

Return to “Ask for Help (v1)”