@ -785,12 +785,14 @@ CreateArrayOfTabs() {
Message = Creating an Array of All Chrome Tabs
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
DriverTitleArray := [] ; Create an array
; Create an arrays
DriverTitleArray := []
DriverURLArray := []
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){
try Title := Driver.Title
try URL := Driver.URL
@ -802,6 +804,7 @@ CreateArrayOfTabs() {
return
}
*/
; Msgbox % "TotalTabsFound: " TotalTabsFound
; if(DevMode)
; Msgbox % "TotalTabsFound: " TotalTabsFound
@ -813,14 +816,18 @@ CreateArrayOfTabs() {
; Sleep, 1000
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
TabEndTimeArray .= TabEndTime . ","
@ -831,16 +838,6 @@ CreateArrayOfTabs() {
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)
break
; TimeToGrabCurrentTab := A_TickCount - StartTime
@ -855,63 +852,26 @@ CreateArrayOfTabs() {
; TimeToGrabCurrentTab := A_TickCount - StartTime
; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab
; 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(URLPositionInArray = 1){
FirstURLPosition := 1
}
if(URLPositionInArray = 2){
SecondURLPosition := 1
}
if(URLPositionInArray = 3){
ThirdURLPosition := 1
}
if(URLPositionInArray = 4){
FourthURLPosition := 1
}
; Msgbox % "PositionInArray: " PositionInArray
; ArrayContainsURL += 1
if(HasVal(DriverURLArray, URL)){ ; returns position of value in array
Continue
}
; TimeToCheckArray := A_TickCount - StartTime
; Msgbox % "ArrayContainsURL: " ArrayContainsURL
if(Title != "")
DriverTitleArray.Push(Title)
if(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.
} ; end of loop
; Iterate from 1 to the end of the array:
Loop % DriverURLArray.Length()
{
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")
; TimeToLoopThroughAllTabs := A_TickCount - StartTime
; Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs%
; SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(Message)
return
} ; /FUNC
@ -943,7 +903,7 @@ if(TotalTabsFound = 1){
}
; -------------------------------NavigateFromBaseURLTo-------------------------------
NavigateFromBaseURLTo(URL,PageTitle := "New Tab "){
NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme "){
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
Status := CheckSeleniumDriver()
if(Status)
@ -952,25 +912,52 @@ if(TotalTabsFound = 1){
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){
URLBase := StrReplace(URL,"https://","")
URLBase := StrSplit(URLBase, "/")
URLBase := StrReplace(URL,"https://","") ; remove beginning of URL
URLBase := StrSplit(URLBase, "/") ; remove text after url base
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%"
DriverURLArray.Push(URL) ; Append an item to the array
DriverURLArray.Push(URL) ; Append the new url to the array
NewTabCreated := 1
sleep, 1000
}
/*
else, {
Message = %URLBase% is the urlbase and it's within the DriverURLArray
DevModeMsgBox(Message)
}
*/
; msgbox,
Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
DevModeMsgBox(Message)
TabFoundSuccessfully :=
@ -986,18 +973,34 @@ if(TotalTabsFound = 1){
try CurrentTabURL := driver.Url
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
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
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
; 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.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
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
try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL
@ -1007,6 +1010,7 @@ if(TotalTabsFound = 1){
Return "Failed"
}
}
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
}
; msgbox, no error caught
; }