Added extra check to Chrome Tab Activation Function and extra debug error logging

main
Yuriy 2 years ago
parent 89c1042e01
commit 694c440a6a

@ -217,13 +217,13 @@ TimedToolTip(Text, x="", y="",RemoveAfterTime:=2000, SetWhichToolTip="") {
Func_LogErrorsToTextFile(Text){
; ErrorLoggingFile := Filepath
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
text =
(
text =
(
---------------%TodayDate%---------------
%Text%
---------------%TodayDate%---------------
%Text%
)
)
FileAppend, %Text%, %ErrorLoggingFilePath%
}
; -------------------------------/LogErrorsToTextFile-------------------------------
@ -730,26 +730,6 @@ CheckIfUpdateAvailable(Filepath, CurrentVersion){
FindUpdateChangeLog(Filepath){
FileRead, ScriptUpdateContents, %Filepath%
; Set Variables
ChangelogStart =;---Changelog------------------------------------------------------
ChangelogEnd =;---/Changelog------------------------------------------------------
; Msgbox % "ScriptUpdateContents: " ScriptUpdateContents
ChangeLog := StrSplit(ScriptUpdateContents, ChangelogStart)
ChangeLog := ChangeLog[2]
ChangeLog := StrSplit(ChangeLog, ChangelogEnd)
ChangeLog := ChangeLog[1]
Return Changelog
}
CheckSeleniumDriver(){
try Driver := SChrome_Get("", ChromeProfile := "") ; open new tab page with with specified profile
catch e {
@ -790,6 +770,9 @@ SeleniumConnectToActiveTab(IP_Port := "127.0.0.1:9222"){
return Driver
}
/*
*/
CreateArrayOfChromeTabs() {
Message = Creating an Array of All Chrome Tabs
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -895,10 +878,12 @@ CreateArrayOfChromeTabs() {
return
}
InputFilePathIntoOpenWindow(Filepath){
/*
*/
InputFilePathIntoOpenWindow(Filepath){
; Msgbox % "Filepath: " Filepath
Message = Waiting for "Open" window to appear to input filepath into
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -969,6 +954,10 @@ ActivateChromeTab(URL){
; NumberOfTabLoops := Driver.Windows.Count + 2
loop % NumberOfTabActivationLoops { ; loop through tabs to find matching tab
Message = Looping through tabs to activate with: %URLBase%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try driver.SwitchToNextWindow()
; sleep, 1000
@ -988,8 +977,8 @@ ActivateChromeTab(URL){
}
; / loop through tabs
}
return "Failed"
}
return "Failed"
}
/*ActivateChromeTab(URL){
@ -1014,8 +1003,12 @@ return "Failed"
NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
Status := CheckSeleniumDriver()
if(Status)
if(Status){
Message = Failed to Connect to Chrome. Please Check for any open dialog boxes or ChromeDriver being out of date.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
; CreateArrayOfChromeTabs() ; moved to the end of checkseleniumdriver()
}
@ -1044,11 +1037,16 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
if(!HasSubstringVal(ChromeTabsURLArray, URLBase))
{
; DevModeMsgBox("Creating new tab")
Message = Tab for %urlBase% does not exist. Creating new tab with URL: %URL%
try, run "%ChromeFilepath%" "%URL%"
ChromeTabsURLArray.Push(URL) ; Append the new url to the array
NewTabCreated := 1
sleep, 1000
}
else, {
Message = %URLBase% is within ChromeTabsURLArray. Trying to Activate.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
; message = NewTabCreated: %NewTabCreated%
; DevModeMsgBox(message)
@ -1059,6 +1057,25 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
try currentURL := driver.url
Message = Failed to switch active tab to %URLBase%. Current tab is: %currentURL%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
CheckForAlerts()
; create a new tab and try to switch to it again
Message = Creating new tab with URL: %URL%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try, run "%ChromeFilepath%" "%URL%"
ChromeTabsURLArray.Push(URL) ; Append the new url to the array
NewTabCreated := 1
sleep, 1000
status := ActivateChromeTab(URLBase)
if(Status = "Failed"){
Message = Failed to activate tab for %urlBase% after 2 atteppts. Chrome stuck on a dialog box of some sort?
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
; message = ActivateChromeTab Status: %status%
; DevModeMsgBox(message)
@ -1083,16 +1100,14 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL
catch e {
Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
Message = Failed to Navigate to URL: %URL%. Please Check for any open dialog boxes or ChromeDriver being out of date.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
}
; msgbox, no error caught
; }
Return
}
@ -1100,7 +1115,7 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
CheckForAlerts(){
Message = Checking for Any Obstructing Alerts in Chrome
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
status := 1
try driver.SwitchToAlert()
@ -1123,11 +1138,11 @@ CheckForAlerts(){
}
CheckURLForSubstring(Substring){
try CurrentTabURL := driver.url
try CurrentTabURL := driver.url
if(InStr(CurrentTabURL, Substring))
if(InStr(CurrentTabURL, Substring))
return "True"
else,
else,
return
}
@ -1210,9 +1225,11 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
; Save current chrome version to ini file
return Driver
}
; -------------------------------/SChrome_Get-------------------------------
ShowSeleniumErrorMsgbox(){
; -------------------------------/SChrome_Get-------------------------------
/*
*/
ShowSeleniumErrorMsgbox(){
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
Chromeversion := RunCMD(GetChromeVersionCommand)
ChromeVersion := StrReplace(ChromeVersion, "`n", "")
@ -1281,11 +1298,13 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
/*
*/
; -------------------------------FileXPro Get File Attributes-------------------------------
;https://www.autohotkey.com/boards/viewtopic.php?t=59882
; -------------------------------FileXPro Get File Attributes-------------------------------
;https://www.autohotkey.com/boards/viewtopic.php?t=59882
Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails
@ -1328,15 +1347,15 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
If Not ( _FileExt ) ; Filepath not resolved
{
Return
}
}
objShl := ComObjCreate("Shell.Application")
objDir := objShl.NameSpace(_Dir)
objItm := objDir.ParseName(_FileExt)
objShl := ComObjCreate("Shell.Application")
objDir := objShl.NameSpace(_Dir)
objItm := objDir.ParseName(_FileExt)
If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable
{
If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable
{
i:=-1, xDetails:={}, xDetails.SetCapacity(309)
While ( i++ < 309 )
@ -1345,17 +1364,17 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
}
xDetails.Delete("")
}
}
If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind
{
If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind
{
Return
}
}
i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11)
i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11)
While ( i++ < nParams )
{
While ( i++ < nParams )
{
Prop := p[i]
If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
@ -1369,19 +1388,19 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
Continue
}
}
}
fex.SetCapacity(-1)
Return fex
fex.SetCapacity(-1)
Return fex
} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; GuiButtonIcon
;------------------------------------------------
GuiButtonIcon(Handle, File, Index := 1, Options := "")
{
; GuiButtonIcon
;------------------------------------------------
GuiButtonIcon(Handle, File, Index := 1, Options := "")
{
RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 :
RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 :
RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S :
@ -1400,13 +1419,13 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
NumPut( A, button_il, 16 + Psz, DW ) ; Alignment
SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle%
return IL_Add( normal_il, File, Index )
}
}
; \GuiButtonIcon
;------------------------------------------------
; \GuiButtonIcon
;------------------------------------------------
ToggleTestingMode(){
ToggleTestingMode(){
IniRead, TestingMode, Settings.ini, General, TestingMode, 0
; Msgbox % "TestingMode: " TestingMode
@ -1414,9 +1433,9 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
IniWrite, 0, Settings.ini, General, TestingMode
else,
IniWrite, 1, Settings.ini, General, TestingMode
}
}
ToggleManualSubmit(){
ToggleManualSubmit(){
IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0
; Msgbox % "TestingMode: " TestingMode
@ -1424,10 +1443,10 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
IniWrite, 0, Settings.ini, General, ManualSubmit
else,
IniWrite, 1, Settings.ini, General, ManualSubmit
}
}
ToggleDevMode(){
ToggleDevMode(){
IniRead, DevMode, Settings.ini, General, DevMode, 0
; Msgbox % "TestingMode: " TestingMode
@ -1435,10 +1454,10 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
IniWrite, 0, Settings.ini, General, DevMode
else,
IniWrite, 1, Settings.ini, General, DevMode
}
}
FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones
FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones
/*\b Backspace
\f Form Feed
\n New Line - done
@ -1638,8 +1657,8 @@ Selenium_LoopToClickID(IDName,NumOfLoops:=1,SleepLength:=1000){
}
sleep, %SleepLength%
Continue
}
Return
}
Return
}
}
@ -1653,8 +1672,8 @@ Selenium_LoopToClickName(ElementName,NumOfLoops:=1,SleepLength:=1000){
}
sleep, %SleepLength%
Continue
}
Return
}
Return
}
}
@ -1668,8 +1687,8 @@ Selenium_LoopToSendValueToID(IDName,NumOfLoops:=1,SleepLength:=1000,StringTextCo
}
sleep, %SleepLength%
Continue
}
Return
}
Return
}
}
; Selenium_LoopToSendValueByName(ElementName:="NAME",NumOfLoops:=2,SleepLength:=1000,StringTextContent:="TEXT")
@ -1712,8 +1731,8 @@ Selenium_LoopToClickXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
}
sleep, %SleepLength%
Continue
}
Return
}
Return
}
}
@ -1752,8 +1771,8 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
}
sleep, %SleepLength%
Continue
}
Return
}
Return
}
}
@ -1762,109 +1781,117 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
; -------------------------------Javascript-------------------------------
ReturnAndDisplayJSData(jsref){
; msgbox, here goes
; https://www.w3schools.com/jsref/dom_obj_all.asp
; -----TEXT CONTENT-----
js = return %jsref%.textContent;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3,.TextContent:,%status%
OnMessage(0x44, "")
; msgbox, here goes
; https://www.w3schools.com/jsref/dom_obj_all.asp
; -----TEXT CONTENT-----
js = return %jsref%.textContent;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3,.TextContent:,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----VALUE-----
js = return %jsref%.value;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----VALUE-----
js = return %jsref%.value;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3,.value:,%status%
OnMessage(0x44, "")
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3,.value:,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----INNERTEXT-----
js = return %jsref%.innerText;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----INNERTEXT-----
js = return %jsref%.innerText;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerText,%status%
OnMessage(0x44, "")
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerText,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
}
; -----OuterText-----
js = return %jsref%.outerText;
try status := driver.executeScript(js)
; -----OuterText-----
js = return %jsref%.outerText;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerText,%status%
OnMessage(0x44, "")
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerText,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
;-----innerHTML-----
js = return %jsref%.innerHTML;
try status := driver.executeScript(js)
;-----innerHTML-----
js = return %jsref%.innerHTML;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerHTML,%status%
OnMessage(0x44, "")
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerHTML,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
}
; -----outerHTML-----
js = return %jsref%.outerHTML;
try status := driver.executeScript(js)
; -----outerHTML-----
js = return %jsref%.outerHTML;
try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerHTML,%status%
OnMessage(0x44, "")
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerHTML,%status%
OnMessage(0x44, "")
/*
*/
IfMsgBox Yes,{
} Else IfMsgBox No, {
@ -1876,8 +1903,8 @@ IfMsgBox Yes,{
}
/*
*/
OnMsgBoxJSReturnData() {
DetectHiddenWindows, On
Process, Exist

Loading…
Cancel
Save