@ -104,9 +104,9 @@ UpdateScript(){
; -------------------------------SaveOrPostProgress-------------------------------
; -------------------------------SaveOrPostProgress-------------------------------
; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos"
; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos"
SaveOrPostProgress(Message:="",PostType:=""){
SaveOrPostProgress(Message:="",PostType:=""){
MessageBU := Message
MessageBU := Message
; Msgbox % "PostType: " PostType
; Msgbox % "PostType: " PostType
@ -138,9 +138,9 @@ UpdateScript(){
}
}
; -------------------------------/SaveOrPostProgress-------------------------------
; -------------------------------/SaveOrPostProgress-------------------------------
TakeScreenshotOfPage(SaveFilepath := ""){
TakeScreenshotOfPage(SaveFilepath := ""){
if(!ScreenshotResult)
if(!ScreenshotResult)
return
return
@ -785,12 +785,14 @@ CreateArrayOfTabs() {
Message = Creating an Array of All Chrome Tabs
Message = Creating an Array of All Chrome Tabs
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
DriverTitleArray := [] ; Create an array
; Create an arrays
DriverTitleArray := []
DriverURLArray := []
DriverURLArray := []
try TotalTabsFound := Driver.Windows.Count
try TotalTabsFound := Driver.Windows.Count
; DevModeMsgBox(TotalTabsFound)
; if only 1 tab exists, grab info, push to array and exit early
/* ; if only 1 tab exists, grab info, push to array and return
if(TotalTabsFound = 1){
if(TotalTabsFound = 1){
try Title := Driver.Title
try Title := Driver.Title
try URL := Driver.URL
try URL := Driver.URL
@ -802,6 +804,7 @@ CreateArrayOfTabs() {
return
return
}
}
*/
; Msgbox % "TotalTabsFound: " TotalTabsFound
; Msgbox % "TotalTabsFound: " TotalTabsFound
; if(DevMode)
; if(DevMode)
; Msgbox % "TotalTabsFound: " TotalTabsFound
; Msgbox % "TotalTabsFound: " TotalTabsFound
@ -813,14 +816,18 @@ CreateArrayOfTabs() {
; Sleep, 1000
; Sleep, 1000
StartTime := A_TickCount
StartTime := A_TickCount
Loop, {
Message = Creating an Array of All Chrome Tabs`nCurrent Loop: %A_index%/%TotalTabsFound% (Cannot loop through unloaded tabs)`nSometimes might get stuck for a short while if there is something loading in active tab
TooltipThis(Message)
; SaveOrPostProgress(Message:=URL,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
; if(ArrayContainsURL = 3 AND A_index > TotalTabsFound)
; Break
; 5 is arbitrary number to do some extra loops to make sure all tabs are gone through
; most likely not necessary because unloaded tabs cannot be activated
TotalLoops := TotalTabsFound + 5
Loop % TotalLoops {
Message = Creating an Array of All Chrome Tabs`nCurrent Loop: %A_index%/%TotalLoops% (Cannot check on unloaded tabs)`nSometimes might get stuck for a short while if there is something loading in active tab
TooltipThis(Message)
; exit after looping through 1 tab, if only 1 tab found in count
if(TotalTabsFound = 1 AND A_index > TotalTabsFound)
return
TabEndTime := A_TickCount - TabFoundStartTime
TabEndTime := A_TickCount - TabFoundStartTime
TabEndTimeArray .= TabEndTime . ","
TabEndTimeArray .= TabEndTime . ","
@ -831,16 +838,6 @@ CreateArrayOfTabs() {
TabFoundStartTime := A_TickCount
TabFoundStartTime := A_TickCount
IndexMinus3 := A_index - 3
; if(FirstURLPosition AND SecondURLPosition AND ThirdURLPosition AND IndexPlus3 > TotalTabsFound OR A_index = 30) {
if(IndexMinus3 > TotalTabsFound) {
; DevModeMsgBox("First 3 tabs found. Breaking")
; Msgbox % "A_index: " A_index "`n" "IndexPlus3: " IndexPlus3
break
}
if(TotalTabsFound < 4 AND A_index = 4)
if(TotalTabsFound < 4 AND A_index = 4)
break
break
; TimeToGrabCurrentTab := A_TickCount - StartTime
; TimeToGrabCurrentTab := A_TickCount - StartTime
@ -855,63 +852,26 @@ CreateArrayOfTabs() {
; TimeToGrabCurrentTab := A_TickCount - StartTime
; TimeToGrabCurrentTab := A_TickCount - StartTime
; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab
; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab
; VAR := HasVal(DriverURLArray, STRINGVAR) ; returns position of value in array
; VAR := HasVal(DriverURLArray, STRINGVAR) ; returns position of value in array
if(HasVal(DriverURLArray, URL)) ; returns position of value in array
{
URLPositionInArray := HasVal(DriverURLArray, URL)
if(HasVal(DriverURLArray, URL)){ ; returns position of value in array
if(URLPositionInArray = 1){
Continue
FirstURLPosition := 1
}
if(URLPositionInArray = 2){
SecondURLPosition := 1
}
if(URLPositionInArray = 3){
ThirdURLPosition := 1
}
if(URLPositionInArray = 4){
FourthURLPosition := 1
}
; Msgbox % "PositionInArray: " PositionInArray
; ArrayContainsURL += 1
}
}
; TimeToCheckArray := A_TickCount - StartTime
; Msgbox % "ArrayContainsURL: " ArrayContainsURL
if(Title != "")
if(Title != "")
DriverTitleArray.Push(Title)
DriverTitleArray.Push(Title)
if(URL != "")
if(URL != "")
DriverURLArray.Push(URL)
DriverURLArray.Push(URL)
/*
if(TotalTabsFound = 1){
TimeToKickOut := A_TickCount - StartTime
; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab
; Msgbox % "TimeToCheckArray: " TimeToCheckArray
; Msgbox % "TimeToKickOut: " TimeToKickOut
; MsgBox, %ElapsedTime% milliseconds have elapsed.
; Msgbox % "A_index: " A_index
; DevModeMsgBox("breaking early on loop 1?")
break
} ; if there is only 1 tab, then break out of loop and don't bother looping through same tab
*/
try driver.SwitchToNextWindow ;Focuses Selenium on the newly opened/next window.
try driver.SwitchToNextWindow ;Focuses Selenium on the newly opened/next window.
} ; end of loop
} ; end of loop
; Iterate from 1 to the end of the array:
; TimeToLoopThroughAllTabs := A_TickCount - StartTime
Loop % DriverURLArray.Length()
; Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs%
{
; SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
ARRAYNAMEList .= DriverURLArray[A_Index] . "`n"
; ArrayItem := DriverURLArray[A_Index]
; MsgBox % DriverURLArray[A_Index]
}
; Msgbox % "ARRAYNAMEList: " ARRAYNAMEList
TimeToLoopThroughAllTabs := A_TickCount - StartTime
Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(Message)
; DevModeMsgBox(Message)
return
return
} ; /FUNC
} ; /FUNC
@ -943,7 +903,7 @@ if(TotalTabsFound = 1){
}
}
; -------------------------------NavigateFromBaseURLTo-------------------------------
; -------------------------------NavigateFromBaseURLTo-------------------------------
NavigateFromBaseURLTo(URL,PageTitle := "New Tab "){
NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme "){
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
Status := CheckSeleniumDriver()
Status := CheckSeleniumDriver()
if(Status)
if(Status)
@ -952,25 +912,52 @@ if(TotalTabsFound = 1){
CreateArrayOfTabs()
CreateArrayOfTabs()
}
}
; Msgbox % CreateArrayOfTabs.Length() ; Display total number of items in the array
ArrayLenght := DriverURLArray.Length() ; Save total number of items in the array
; Msgbox % "ArrayLenght: " ArrayLenght
; Iterate from 1 to the end of the array:
/*
Loop % DriverURLArray.Length(){
; ArrayItem := CreateArrayOfTabs[A_Index]
MsgBox % DriverURLArray[A_Index]
}
*/
; message = URL: %URL%
; DevModeMsgBox(message)
if(ReuseTabs){
if(ReuseTabs){
URLBase := StrReplace(URL,"https://","")
URLBase := StrReplace(URL,"https://","") ; remove beginning of URL
URLBase := StrSplit(URLBase, "/")
URLBase := StrSplit(URLBase, "/") ; remove text after url base
URLBase := URLBase[1]
URLBase := URLBase[1]
URLBase := StrReplace(URLBase, "www.","")
URLBase := StrReplace(URLBase, "www.","") ; remove www if there 1
}
}
if(!HasSubstringVal(DriverURLArray, URLBase)) ; returns position of value in array
; Message = URLbase after cleaning: %URLBase%`nOriginal URL: %URL%
; DevModeMsgBox(message)
; check if URLBase is a substring within any of the values in the array
if(!HasSubstringVal(DriverURLArray, URLBase))
{
{
; DevModeMsgBox("Creating new tab")
try, run "%ChromeFilepath%" "%URL%"
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
DriverURLArray.Push(URL) ; Append the new url to the array
NewTabCreated := 1
NewTabCreated := 1
sleep, 1000
sleep, 1000
}
}
/*
else, {
Message = %URLBase% is the urlbase and it's within the DriverURLArray
DevModeMsgBox(Message)
}
*/
; msgbox,
; msgbox,
Message = Finding Tab
Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
DevModeMsgBox(Message)
TabFoundSuccessfully :=
TabFoundSuccessfully :=
@ -986,18 +973,34 @@ if(TotalTabsFound = 1){
try CurrentTabURL := driver.Url
try CurrentTabURL := driver.Url
if(CurrentTabTitle = PageTitle OR InStr(CurrentTabURL, URLBase)){
if(CurrentTabTitle = PageTitle OR InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
Message = Found Tab:.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
DevModeMsgBox(message)
TabFoundSuccessfully := 1
TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
; msgbox %CurrentTabURL% = %URL%
Break
Break
}
}
; / loop through tabs
}
}
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
; Double check that the current tab URL matches the url base
try, CurrentTabURl := driver.url
Message = Reusing Tab. `nCurrentTabURl: %CurrentTabURl%`nURL Navigating to: %URL%
DevModeMsgBox(Message)
try driver.Get(URL) ;Open selected URL
try driver.Get(URL) ;Open selected URL
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
catch e {
catch e {
Message = Failed to Navigate to URL in pre-existing tab`nPlease See Error #5648 for code section
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; SaveDriverURLOFErrorPage()
; Return
; msgbox, error caught. trying something
; msgbox, error caught. trying something
try driver.switchToalert().accept()
try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL
try driver.Get(URL) ;Open selected URL
@ -1007,25 +1010,26 @@ if(TotalTabsFound = 1){
Return "Failed"
Return "Failed"
}
}
}
}
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
}
}
; msgbox, no error caught
; msgbox, no error caught
; }
; }
Return
Return
}
}
; End of Function
; End of Function
; -------------------------------/NavigateFromBaseURL-------------------------------
; -------------------------------/NavigateFromBaseURL-------------------------------
SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together
SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together
try LastWebsitePostURL := driver.URL
try LastWebsitePostURL := driver.URL
return LastWebsitePostURL
return LastWebsitePostURL
}
}
; -------------------------------SChrome_Get-------------------------------
; -------------------------------SChrome_Get-------------------------------
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1")
IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1")
if WinExist("ahk_exe Chrome.exe"){
if WinExist("ahk_exe Chrome.exe"){
WinGet, pid, PID, ahk_exe chrome.exe
WinGet, pid, PID, ahk_exe chrome.exe