@ -153,11 +153,11 @@ UpdateScript(){
; sleep, 5000
if(SaveFilepath = ""){
SaveFilepath := ErrorLoggingDirectory
}
SaveFilepath := ErrorLoggingDirectory
}
; if(!FileExist(SaveFilepath))
FileCreateDir, %SaveFilepath%
; if(!FileExist(SaveFilepath))
FileCreateDir, %SaveFilepath%
/* if(!TakeScreenshotsOfErrors)
Return
@ -947,127 +947,141 @@ if(TotalTabsFound = 1){
}
; -------------------------------NavigateFromBaseURLTo-------------------------------
NavigateFromBaseURLTo(URL,PageTitle := "New Tab" ){
NavigateFromBaseURLTo(URL){
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
Status := CheckSeleniumDriver()
if(Status)
Return "Failed"
CreateArrayOfTabs()
CreateArrayOfTabs() ; store all open tabs to memory for later usage
}
if(ReuseTabs){
URLBase := StrReplace(URL,"https://","")
URLBase := StrSplit(URLBase, "/")
URLBase := URLBase[1]
URLBase := StrReplace(URLBase, "www.","")
}
if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs
URLBase := StrReplace(URL,"https://","")
URLBase := StrSplit(URLBase, "/")
URLBase := URLBase[1]
URLBase := StrReplace(URLBase, "www.","")
}
if(!HasSubstringVal(DriverURLArray, URLBase)) ; returns position of value in array
{
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
sleep, 1 000
}
; msgbox,
if(!HasSubstringVal(DriverURLArray, URLBase)) ; if base url is not in tab array, create new tab and push url to array
{
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
sleep, 2 000
}
; msgbox,
Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
TabFoundSuccessfully :=
TabFoundSuccessfully :=
NumberOfTabLoops := DriverURLArray.Length()
NumberOfTabLoops := DriverURLArray.Length()
; NumberOfTabLoops := Driver.Windows.Count + 2
loop % NumberOfTabLoops { ; loop through tabs to find matching tab
try driver.SwitchToNextWindow()
; NumberOfTabLoops := Driver.Windows.Count + 2
loop % NumberOfTabLoops { ; loop through tabs to find matching tab
try driver.SwitchToNextWindow()
; sleep, 1000
; msgbox, looping through tabs
try CurrentTabTitle := driver.window.title
try CurrentTabURL := driver.Url
; sleep, 1000
; msgbox, looping through tabs
try CurrentTabTitle := driver.window.title
if(CurrentTabTitle = PageTitle OR InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
Break
}
}
; caused by tab being manually closed. Not sure if this is the only cause though.
if(CurrentTabTitle = "") {
Message = CurrentTabTitle: %CurrentTabTitle%
DevModeMsgBox(Message)
Message = CurrenttabURL: %CurrentTabURL%
DevModeMsgBox(Message)
; try driver.SwitchToNextWindow
Continue
}
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
Break
}
}
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.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
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"
}
Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
; msgbox, no error caught
; }
}
; msgbox, no error caught
; }
Return
}
; End of Function
; -------------------------------/NavigateFromBaseURL-------------------------------
Return
}
; 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
try LastWebsitePostURL := driver.URL
}
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
}
; -------------------------------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
for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){
if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){
break
}
; -------------------------------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
for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){
if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){
break
}
}
if (Port=""){
MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection?
IfMsgBox, Yes
{
Message = Restarting Chrome in Debug Mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if (Port=""){
MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection?
IfMsgBox, Yes
{
Message = Restarting Chrome in Debug Mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
While(WinExist("ahk_exe chrome.exe")) {
WinClose, ahk_exe chrome.exe
}
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
While(WinExist("ahk_exe chrome.exe")) {
WinClose, ahk_exe chrome.exe
}
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
}
}
}
; ; yuriy's settings
; IniRead, ChromeFilepath, C:\Users\%A_username%\Documents\Autohotkey\Lib\ScriptSettings.ini, Selenium, %A_Computername%, %A_Space%
; ; yuriy's settings
; IniRead, ChromeFilepath, C:\Users\%A_username%\Documents\Autohotkey\Lib\ScriptSettings.ini, Selenium, %A_Computername%, %A_Space%
; ; Establish Variable with Filepath to be used throughout the script
; if(ChromeFilepath = ""){
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
}
else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
}
; ; Establish Variable with Filepath to be used throughout the script
; if(ChromeFilepath = ""){
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
}
else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
}
if(ChromeFilepath = ""){
@ -1408,13 +1422,22 @@ SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab
FindAndActivateTab(TabURL){
DevModeMsgBox(TabURL)
Loop, {
if(A_index = 30)
break
try CurrentTabTitle := driver.window.title
if(CurrentTabTitle = "") ; caused by tab being manually closed. Not sure if this is the only cause though.
{
; DevModeMsgBox("currenttabtutle is blank")
try driver.SwitchToNextWindow
Continue
}
; DevModeMsgBox(CurrentTabTitle)
try CurrentTabURL := driver.Url
DevModeMsgBox(CurrentTabURL)
if(CurrentTabURL = TabURL)
Break