Reworked pre-existing tab indexing for re-using tabs

pull/2/head
Yuriy 2 years ago
parent 38295d8430
commit 1048b80de4

@ -2214,7 +2214,7 @@ if(!InStr(LocalsPostPageURL, "/share/post")){
} }
; replace any double slashes that migth have come from the combining ; replace any double slashes that migth have come from the combining
LocalsPostPageURL := StrReplace(LocalsPostPageURL, "//", "/") ; LocalsPostPageURL := StrReplace(LocalsPostPageURL, "//", "/")
Status := NavigateFromBaseURLTo(LocalsPostPageURL) Status := NavigateFromBaseURLTo(LocalsPostPageURL)
@ -5109,7 +5109,7 @@ if(VideoThumbFilepath != "") {
; @todo: Add a check to see if progress gets stuck ; @todo: Add a check to see if progress gets stuck
; Check Upload Percentage ; Check Upload Percentage
TooltipThis("Waiting for Video to Finish Uploading`nChecking Progress Every 5 Seconds") TooltipThis("Waiting for Video to Finish Uploading")
Loop, %Number_of_loops_to_Check_Upload_status% { Loop, %Number_of_loops_to_Check_Upload_status% {
sleep, %Time_Between_Loops_Upload_Status% sleep, %Time_Between_Loops_Upload_Status%
@ -5167,7 +5167,7 @@ js = document.getElementById('submitForm').click();
try driver.executeScript(js) ; try driver.executeScript(js) ;
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
; Select Rumble Only Licensing ; Select Rumble Only Licensing

@ -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,6 +1010,7 @@ 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
; } ; }

Loading…
Cancel
Save