Reworked pre-existing tab indexing for re-using tabs
This commit is contained in:
@@ -2214,7 +2214,7 @@ if(!InStr(LocalsPostPageURL, "/share/post")){
|
||||
}
|
||||
|
||||
; replace any double slashes that migth have come from the combining
|
||||
LocalsPostPageURL := StrReplace(LocalsPostPageURL, "//", "/")
|
||||
; LocalsPostPageURL := StrReplace(LocalsPostPageURL, "//", "/")
|
||||
|
||||
|
||||
Status := NavigateFromBaseURLTo(LocalsPostPageURL)
|
||||
@@ -5109,7 +5109,7 @@ if(VideoThumbFilepath != "") {
|
||||
|
||||
; @todo: Add a check to see if progress gets stuck
|
||||
; 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% {
|
||||
sleep, %Time_Between_Loops_Upload_Status%
|
||||
|
||||
@@ -5167,7 +5167,7 @@ js = document.getElementById('submitForm').click();
|
||||
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
|
||||
|
||||
@@ -104,9 +104,9 @@ UpdateScript(){
|
||||
|
||||
|
||||
|
||||
; -------------------------------SaveOrPostProgress-------------------------------
|
||||
; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos"
|
||||
SaveOrPostProgress(Message:="",PostType:=""){
|
||||
; -------------------------------SaveOrPostProgress-------------------------------
|
||||
; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos"
|
||||
SaveOrPostProgress(Message:="",PostType:=""){
|
||||
|
||||
MessageBU := Message
|
||||
; Msgbox % "PostType: " PostType
|
||||
@@ -138,9 +138,9 @@ UpdateScript(){
|
||||
|
||||
|
||||
|
||||
}
|
||||
; -------------------------------/SaveOrPostProgress-------------------------------
|
||||
TakeScreenshotOfPage(SaveFilepath := ""){
|
||||
}
|
||||
; -------------------------------/SaveOrPostProgress-------------------------------
|
||||
TakeScreenshotOfPage(SaveFilepath := ""){
|
||||
|
||||
if(!ScreenshotResult)
|
||||
return
|
||||
@@ -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
|
||||
|
||||
|
||||
; 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)
|
||||
|
||||
; SaveOrPostProgress(Message:=URL,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
|
||||
; if(ArrayContainsURL = 3 AND A_index > TotalTabsFound)
|
||||
; Break
|
||||
|
||||
; 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
|
||||
}
|
||||
; TimeToCheckArray := A_TickCount - StartTime
|
||||
|
||||
; Msgbox % "ArrayContainsURL: " ArrayContainsURL
|
||||
|
||||
if(HasVal(DriverURLArray, URL)){ ; returns position of value in array
|
||||
Continue
|
||||
}
|
||||
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
if(ReuseTabs){
|
||||
URLBase := StrReplace(URL,"https://","")
|
||||
URLBase := StrSplit(URLBase, "/")
|
||||
URLBase := URLBase[1]
|
||||
URLBase := StrReplace(URLBase, "www.","")
|
||||
; 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]
|
||||
}
|
||||
|
||||
if(!HasSubstringVal(DriverURLArray, URLBase)) ; returns position of value in array
|
||||
|
||||
*/
|
||||
|
||||
; message = URL: %URL%
|
||||
; DevModeMsgBox(message)
|
||||
|
||||
if(ReuseTabs){
|
||||
URLBase := StrReplace(URL,"https://","") ; remove beginning of URL
|
||||
URLBase := StrSplit(URLBase, "/") ; remove text after url base
|
||||
URLBase := URLBase[1]
|
||||
URLBase := StrReplace(URLBase, "www.","") ; remove www if there 1
|
||||
}
|
||||
|
||||
; 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,25 +1010,26 @@ if(TotalTabsFound = 1){
|
||||
Return "Failed"
|
||||
}
|
||||
}
|
||||
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
||||
}
|
||||
; msgbox, no error caught
|
||||
; }
|
||||
|
||||
|
||||
Return
|
||||
}
|
||||
; End of Function
|
||||
; -------------------------------/NavigateFromBaseURL-------------------------------
|
||||
}
|
||||
; End of Function
|
||||
; -------------------------------/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
|
||||
|
||||
return LastWebsitePostURL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
; -------------------------------SChrome_Get-------------------------------
|
||||
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
|
||||
; -------------------------------SChrome_Get-------------------------------
|
||||
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
|
||||
IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1")
|
||||
if WinExist("ahk_exe Chrome.exe"){
|
||||
WinGet, pid, PID, ahk_exe chrome.exe
|
||||
|
||||
Reference in New Issue
Block a user