From c3dabf54b4ccf4932570fd5d9462199796d33286 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Mon, 30 Jan 2023 22:51:15 -0500 Subject: [PATCH] expanded error checking functions --- Freedomain Social Media Poster.ahk | 68 +++++++++++++++--------------- Lib/SharedFunctions.ahk | 61 +++++++++++++++++---------- 2 files changed, 73 insertions(+), 56 deletions(-) diff --git a/Freedomain Social Media Poster.ahk b/Freedomain Social Media Poster.ahk index 861af6b..a4782f9 100644 --- a/Freedomain Social Media Poster.ahk +++ b/Freedomain Social Media Poster.ahk @@ -2007,9 +2007,9 @@ if(InStr(CurrentTabURL, "/login")){ Return Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + if(Status){ + Return + } Message = Checking Login Status SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") @@ -2227,9 +2227,9 @@ if(Status){ Return Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + if(Status){ + Return + } sleep, 1000 @@ -2455,7 +2455,7 @@ if(Status){ ; -------------------------------Locals------------------------------- PostToLocals: CurrentSite := "Locals" - + ; DevModeMsgBox("clik ok to continue") ; @todo: Add auto-login to locals SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile") @@ -2472,10 +2472,10 @@ if(Status){ if(Status = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } sleep, 1000 Message = Checking Login Status @@ -2668,10 +2668,10 @@ if(Status){ if(URLAttempt = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } sleep, 1000 Message = Checking Login Status SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") @@ -2779,10 +2779,10 @@ if(Status){ if(URLAttempt = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } ; Loop a bunch of times for page to load SaveOrPostProgress(Message:="Waiting for Page to Load Fully",PostType:="Tooltip,ErrorLoggingTextFile") loop, 12 { @@ -3040,10 +3040,10 @@ if(Status){ if(URLAttempt = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } Message = Checking for Content from Previous Post @@ -3232,9 +3232,9 @@ if(Status){ Return Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + if(Status){ + Return + } sleep, 1000 SaveOrPostProgress(Message:="Checking Login Status",PostType:="Tooltip,ErrorLoggingTextFile") @@ -3387,10 +3387,10 @@ if(Status){ if(URLAttempt = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } Message = Inputting Post Content @@ -3775,10 +3775,10 @@ CurrentSite := "Twetch" if(URLAttempt = "Failed") Return -Status := CheckCurrentTabForCurrentSite() -if(Status){ - Return -} + Status := CheckCurrentTabForCurrentSite() + if(Status){ + Return + } sleep, 1000 diff --git a/Lib/SharedFunctions.ahk b/Lib/SharedFunctions.ahk index 8b6e2ff..da6d76b 100644 --- a/Lib/SharedFunctions.ahk +++ b/Lib/SharedFunctions.ahk @@ -948,21 +948,21 @@ if(TotalTabsFound = 1){ ToolTip, } -CheckCurrentTabForCurrentSite(){ -try CurrentTabURL := driver.url + CheckCurrentTabForCurrentSite(){ + try CurrentTabURL := driver.url -if(!InStr(CurrentTabURL, "CurrentSite")){ - Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on. - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - return "Failed" -} + if(!InStr(CurrentTabURL, CurrentSite)){ + Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on. + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + return "Failed" + } -; msgbox % InStr(CurrentTabURL,CurrentSite) + ; msgbox % InStr(CurrentTabURL,CurrentSite) -} + } ; -------------------------------NavigateFromBaseURLTo------------------------------- @@ -1153,16 +1153,20 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ run, %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL% } + ; Driver.Timeout := 1000 Driver := ComObjCreate("Selenium.ChromeDriver") Driver.SetCapability("debuggerAddress", IP_Port) + + SaveOrPostProgress(Message:="Trying to connect to Chrome.`nIf stuck here check for dialog popups or your ChromeDriver`nClose chrome to break out of program being stuck.",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar") + + ; set selenium timeout to 1 second, instead of default 5 seconds + + try Driver.Start() catch e { - ShowSeleniumErrorMsgbox() + } - } ; end of catch - - ; Save current chrome version to ini file return Driver } ; -------------------------------/SChrome_Get------------------------------- @@ -1172,6 +1176,24 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ Chromeversion := RunCMD(GetChromeVersionCommand) ChromeVersion := StrReplace(ChromeVersion, "`n", "") + Message = Failed to connect to Chrome + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + +/* + ; check for alert popup + try alertText := driver.SwitchToAlert().Text + ; DevModeMsgBox(alertText) + if(alertText){ + Message = Alert Popup Text: %alertText% + SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,ErrorSummaryVar") + SaveOrPostProgress(Message:="Chrome stuck on alert popup",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + DevModeMsgBox("alert popup found") + } + + */ + + ; Msgbox % "alertText: " alertText + ; Clipboard := ChromeVersion ; Msgbox % "Chromeversion: " Chromeversion IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% @@ -1181,7 +1203,7 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") OnMessage(0x44, "OnMsgBoxChromeDriverFailed") - MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up .pdf file with instructions for updating chromedriver.exe`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion% + MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload with your Last Post`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up installation instructions in your default browser.`n`n Information:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion% OnMessage(0x44, "") IfMsgBox Yes, { @@ -1189,18 +1211,13 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ Reload } Else IfMsgBox No, { run, https://chromedriver.chromium.org/downloads + run, "%A_ScriptFullPath%" "LastPost" ExitApp ; open chromedriver site } Else IfMsgBox Cancel, { - URL = https://freedomainplaylists.com/wp-content/FreedomainScripts/Update`%20Selenium`%20ChromeDriver.pdf - Filepath = %A_ScriptDir%\Lib\Update Selenium ChromeDriver.pdf - if(!FileExist(Filepath)){ - UrlDownloadToFile, %URL%, %Filepath% - - run, %Filepath% - } + run, "https://git.zinchuk.xyz/yuriy/Freedomain-Social-Media-Poster#installation" + run, "%A_ScriptFullPath%" "LastPost" ExitApp - } }