Reworked Gab.com Login check and small rework of activating of newly created tabs

main
Yuriy 2 years ago
parent 05b2a4d862
commit 03a93f6570

@ -2643,51 +2643,38 @@ if(InStr(CurrentTabURL, "/login")){
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
try CurrentTabURL := driver.Url
if(!InStr(CurrentTabURL, "/compose")){
Message = Login Cookies Expired. Trying to Re-Login
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; navigate to login page
url = https://gab.com/auth/sign_in
try driver.Get(url) ;Open selected URL
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
sleep, 1500 ; sleep long enough for password manager to input password
Xpath = //button[normalize-space()='Log in']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
SaveOrPostProgress(Message:="Failed to Login. Please Login Manually",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
; navigate to post input page
URLAttempt := NavigateFromBaseURLTo(GabPostURL)
if(URLAttempt = "Failed")
Return
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
}
; Message = Inputting Post ; Message = Inputting Post
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Checking Login Status",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //body/div[@id='gabsocial']/div/div/div/div/div/div[2]/a[1]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=500)
if(!Status){ ; if successfully clicked on login button, we are logged out
Message = Login Cookies Expired. Trying to Re-Login
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding ; New post input box
Xpath = //button[normalize-space()='Log in'] Xpath = //div[@data-block='true']//div
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
sleep, 2000 if(Status){
URLAttempt := NavigateFromBaseURLTo("https://gab.com/compose") SaveOrPostProgress(Message:="Login Expired",PostType:="Tooltip,ErrorLoggingTextFile")
driver.Get("https://gab.com/auth/sign_in") ;go to login page
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
if(AutoLogin){
SaveOrPostProgress(Message:="Checking if chrome input email address",PostType:="Tooltip,ErrorLoggingTextFile")
js = return document.querySelector("#user_email").value;
status := driver.executeScript(js)
if(StrLen(Status) > 0){
SaveOrPostProgress(Message:="Clicking Login Button",PostType:="Tooltip,ErrorLoggingTextFile")
js = document.querySelector("button[name='button']").click()
status := driver.executeScript(js)
return
}
}
else, {
SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
} }
Message = Inputting Post Message = Inputting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

@ -788,6 +788,7 @@ CreateArrayOfTabs() {
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 exit early
if(TotalTabsFound = 1){ if(TotalTabsFound = 1){
@ -813,7 +814,7 @@ CreateArrayOfTabs() {
StartTime := A_TickCount StartTime := A_TickCount
Loop, { 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 Message = Creating an Array of All Chrome Tabs`nCurrent Loop: %A_index%/%TotalTabsFound%`nSometimes might get stuck for a short while if there is something loading in active tab
TooltipThis(Message) TooltipThis(Message)
; SaveOrPostProgress(Message:=URL,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar") ; SaveOrPostProgress(Message:=URL,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
@ -851,6 +852,9 @@ CreateArrayOfTabs() {
try Title := Driver.Title try Title := Driver.Title
try URL := Driver.URL try URL := Driver.URL
; DevModeMsgBox(Title)
; DevModeMsgBox(URL)
; 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
@ -915,7 +919,7 @@ if(TotalTabsFound = 1){
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(Message) ; DevModeMsgBox(Message)
return return
; / END OF FUNC ; / END OF FUNC
} }
InputFilePathIntoOpenWindow(Filepath){ InputFilePathIntoOpenWindow(Filepath){
@ -962,14 +966,37 @@ if(TotalTabsFound = 1){
URLBase := StrReplace(URLBase, "www.","") URLBase := StrReplace(URLBase, "www.","")
} }
if(!HasSubstringVal(DriverURLArray, URLBase)) ; if base url is not in tab array, create new tab and push url to array ; if base url is not in tab array, create new tab and push url to array
if(!HasSubstringVal(DriverURLArray, URLBase))
{ {
try, run "%ChromeFilepath%" "%URL%" try CurrentTabTitle := driver.window.title
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1 ; if currently in new tab navigate to the site in the current tab
sleep, 2000 if(CurrentTabTitle = "New Tab"){
try driver.Get(URL) ;Open selected URL
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
catch e {
; msgbox, error caught. trying something
try driver.switchToalert().accept()
try driver.Get(URL) ;Open selected URL
catch e {
Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
return
}
else, {
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
; sleep, 2000
}
} }
; msgbox,
Message = Finding Tab Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -978,37 +1005,50 @@ if(TotalTabsFound = 1){
NumberOfTabLoops := DriverURLArray.Length() NumberOfTabLoops := DriverURLArray.Length()
; NumberOfTabLoops := Driver.Windows.Count + 2 ; loop through tabs to find matching tab
loop % NumberOfTabLoops { ; loop through tabs to find matching tab loop % NumberOfTabLoops {
try driver.SwitchToNextWindow() try driver.SwitchToNextWindow()
; sleep, 1000 ; sleep, 1000
; msgbox, looping through tabs ; msgbox, looping through tabs
try CurrentTabTitle := driver.window.title try CurrentTabTitle := driver.window.title
try CurrentTabURL := driver.Url
; DevModeMsgBox(CurrentTabURL)
; DevModeMsgBox(CurrentTabTitle)
; caused by tab being manually closed. Not sure if this is the only cause though. ; caused by tab being manually closed. Not sure if this is the only cause though.
if(CurrentTabTitle = "") { if(CurrentTabTitle = "") {
Message = CurrentTabTitle: %CurrentTabTitle% Message = CurrentTabTitle: %CurrentTabTitle%
DevModeMsgBox(Message) ; DevModeMsgBox(Message)
Message = CurrenttabURL: %CurrentTabURL% Message = CurrenttabURL: %CurrentTabURL%
DevModeMsgBox(Message) ; DevModeMsgBox(Message)
; try driver.SwitchToNextWindow ; try driver.SwitchToNextWindow
Continue Continue
} }
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, URLBase)){ if(InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% ; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1 TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle% ; message = %CurrentTabTitle%: %PageTitle%
; DevModeMsgBox(message)
; msgbox %CurrentTabURL% = %URL% ; msgbox %CurrentTabURL% = %URL%
Break Break
} }
} }
; if failed to switch to tab and a new tab was not created, then chrome failed to switch to the tab
; this happens sometimes. most likely to a chromedriver bug or maybe tab being offloaded?
if(!TabFoundSuccessfully AND !NewTabCreated){
; @todo : not sure how to best solve this problem currently. It doesn't happen very often.
; last time it happened was when there were only 2 chrome tabs open, gab + subscribestar. chrome was stuck on subscribestar page and wouldn't nextwindow() to gab
}
; Message = TabFoundSuccessfully: %TabFoundSuccessfully%
; DevModeMsgBox(Message)
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
try driver.Get(URL) ;Open selected URL try driver.Get(URL) ;Open selected URL
@ -1088,8 +1128,8 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
if(!winExist("ahk_exe chrome.exe")){ if(!winExist("ahk_exe chrome.exe")){
message = %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL% message = %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL%
Clipboard := Message ; Clipboard := Message
DevModeMsgBox(message) ; DevModeMsgBox(message)
run, %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL% run, %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL%
} }
@ -1432,7 +1472,7 @@ FindAndActivateTab(TabURL){
; DevModeMsgBox(CurrentTabTitle) ; DevModeMsgBox(CurrentTabTitle)
try CurrentTabURL := driver.Url try CurrentTabURL := driver.Url
DevModeMsgBox(CurrentTabURL) ; DevModeMsgBox(CurrentTabURL)
if(CurrentTabURL = TabURL) if(CurrentTabURL = TabURL)
Break Break

Loading…
Cancel
Save