Yuriy 1 year ago
commit f358623f86

@ -62,7 +62,28 @@ GetChromeVersion(){
} }
GetURLofLatestChromedriver(ChromeVersion){ GetLatestChromeStableVersion(){
; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json")
; converts json data variable into object
parsed := JSON.Load(json_str)
try CurrentChromeStableVersion := parsed.channels.stable.version
if(CurrentChromeStableVersion = ""){
return "Failed to parse json. "
}
return CurrentChromeStableVersion
}
GetDownloadURLOfChromeAndDriver(ChromeVersion){
; Will return the download URL of Chrome for Testing and Chrome Driver, seperated by a ||
; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json") json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json")
@ -87,22 +108,25 @@ GetURLofLatestChromedriver(ChromeVersion){
VersionIndex := A_Index VersionIndex := A_Index
; loop through the platforms to get download URL ; loop through the platforms to get download URL for Chrome
loop % parsed.versions[VersionIndex].downloads.chrome.count() {
if(parsed.versions[VersionIndex].downloads.chrome[A_Index].platform = "win64")
chromeDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
}
; loop through the platforms to get download URL for Chromedriver
loop % parsed.versions[VersionIndex].downloads.chromedriver.count() { loop % parsed.versions[VersionIndex].downloads.chromedriver.count() {
; 64 bit version
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64") if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64")
chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
; 32 bit version
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win32")
chromedriverDLURL32 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
} }
break break
} }
} }
; Msgbox % "chromedriverDLURL32: " chromedriverDLURL32 URLS = %chromeDLURL64%||%chromedriverDLURL64%
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64 return URLS
return chromedriverDLURL32
} }

@ -5,8 +5,6 @@
ShowSeleniumErrorMsgbox(){ ShowSeleniumErrorMsgbox(){
; Clipboard := ChromeVersion
; Msgbox % "Chromeversion: " Chromeversion
IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space%
; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion ; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
; msgbox, failed to connect to Chrome for some reason. ; msgbox, failed to connect to Chrome for some reason.
@ -14,27 +12,23 @@ ShowSeleniumErrorMsgbox(){
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
OnMessage(0x44, "OnMsgBoxChromeDriverFailed") OnMessage(0x44, "OnMsgBoxChromeDriverFailed")
MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up the instructions website for updating Chromedriver.`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion% MsgBox 0x40043, Error, Failed to Connect to Chrome. `nPossible Causes for this:`n1)One of your tabs is stuck loading/refreshing. (Try closing all tabs) `n2)Chrome has a dialogue box open `n3)ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up the instructions website for updating Chromedriver.`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion%
OnMessage(0x44, "") OnMessage(0x44, "")
IfMsgBox Yes, { IfMsgBox Yes, {
; Reload script ; Reload script
Reload Reload
} Else IfMsgBox No, { }
run, https://chromedriver.chromium.org/downloads Else IfMsgBox No, {
ExitApp run, https://chromedriver.chromium.org/downloads
; open chromedriver site ExitApp
} Else IfMsgBox Cancel, { ; open chromedriver site
URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation } Else IfMsgBox Cancel, {
run, %url% URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation
} run, %url%
ExitApp
} }
ExitApp
/* }
*/
; -------------------------------Tab Navigation & Activation------------------------------- ; -------------------------------Tab Navigation & Activation-------------------------------
@ -183,12 +177,12 @@ CheckCurrentTabForCurrentSite(){
if(!InStr(CurrentTabURL, CurrentSite)){ if(!InStr(CurrentTabURL, CurrentSite)){
Message = Chromedriver failed to switch to %CurrentSite%. Current Tab URL: %CurrentTabURL% Message = Chromedriver failed to switch to %CurrentSite%. Current Tab URL: %CurrentTabURL%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
return "Failed" return "Failed"
} }
else, { else, {
Message = CheckCurrentTabForCurrentSite() passed successfully Message = CheckCurrentTabForCurrentSite() passed successfully
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
} }
} }
/* /*
@ -394,12 +388,12 @@ ActivateChromeTab(URL){
if(A_index < 3){ if(A_index < 3){
if(CurrentTabURL = StartingTabURL){ if(CurrentTabURL = StartingTabURL){
Message = Current Tab URL is THE SAME as Starting URL after %A_index% tab switches`nStuck on this tab? Message = Current Tab URL is THE SAME as Starting URL after %A_index% tab switches`nStuck on this tab?
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
CheckForAlerts() CheckForAlerts()
} }
else, { else, {
Message = Current Tab URL is DIFFERENT from starting URL after %A_index% tab switches Message = Current Tab URL is DIFFERENT from starting URL after %A_index% tab switches
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
} }
if(LastActiveTab = CurrentTabURL){ if(LastActiveTab = CurrentTabURL){
@ -429,7 +423,7 @@ ActivateChromeTab(URL){
; / loop through tabs ; / loop through tabs
} }
Message = ActivateChromeTab function failed to activate tab for %urlBase% after looping through %NumberOfTabActivationLoops% tabs Message = ActivateChromeTab function failed to activate tab for %urlBase% after looping through %NumberOfTabActivationLoops% tabs
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
return "Failed" return "Failed"
} }
@ -438,7 +432,7 @@ ActivateChromeTab(URL){
CheckForAlerts(){ CheckForAlerts(){
Message = Checking for Any Obstructing Alerts in Chrome Message = Checking for Any Obstructing Alerts in Chrome
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
status := 1 status := 1
try driver.SwitchToAlert() try driver.SwitchToAlert()
@ -450,7 +444,7 @@ CheckForAlerts(){
if(status){ if(status){
; msgbox, alert found ; msgbox, alert found
; Message = Page Alert Found. Dismissing. ; Message = Page Alert Found. Dismissing.
Message = Page Alert Found. Accepting. Message = Page Alert Found. Accepting so page gets refreshed.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try driver.switchToalert().accept() try driver.switchToalert().accept()
; try driver.switchToalert().dismiss() ; try driver.switchToalert().dismiss()
@ -773,6 +767,29 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
} }
} }
Selenium_TypeTextIntoElement(Text, Xpath){
StrLengthOfPost := StrLen(Text)
Loop % StrLengthOfPost{
Current_Char := SubStr(Text, A_index, 1)
; Msgbox % "Current_Char: " Current_Char
; driver.FindElementByXPath(Xpath).SendKeys(VAR)
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=100,StringTextContent:=Current_Char)
if(Status){
Message = Failed to Input Text
Return Message
}
}
}
SaveDriverURLOFErrorPage(){ ; 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 SaveDriverURLOFErrorPage(){ ; 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 URLOfLastErrorPage := driver.URL try URLOfLastErrorPage := driver.URL
} }

@ -1,58 +1,3 @@
;---ENVIRONMENT---------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
;DetectHiddenWindows, On
#SingleInstance, Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;SetKeyDelay, 500
CoordMode, ToolTip, Screen
CoordMode, Mouse, Screen
;#NoTrayIcon
;Menu, Tray, Icon, ..\Icons\ICONNAMEHERE
;---Notes/Extra Info/#Includes------------------------------------------------------
;---VARIABLES-----------------------------------------------------------------------
;---MAIN SCRIPT---------------------------------------------------------------------
/*
; Example Code:
#include URLDownloadToVar.ahk
URL = https://www.bitchute.com/video/WdxitRyWLZQ/
URLContents := URLDownloadToVar(URL)
TextFileName := yyyy . MM . dd . "_URLToVarDownload"
FileAppend, URLContents, %A_ScriptDir%/%TextFileName%.txt
run, %A_ScriptDir%/%TextFileName%.txt
*/
/*
; Example 2
#SingleInstance,Force
url=https://api.coindesk.com/v1/bpi/currentprice.json ; Plce URL here
Gui,Add,Edit,w800 h500,% URLDownloadToVar(url)
Gui,show,
return
*/
; Example 2
/*#SingleInstance,Force
url=https://fdrpodcasts.com/api/?method=QueryPodcasts&keyword=4500 ; Plce URL here
url := URLDownloadToVar(url)
url := StrReplace(URL, "\/", "/")
Msgbox % "url: " url
Gui,Add,Edit,w800 h500,% URLDownloadToVar(url)
Gui,show,
return
*/
URLDownloadToVar(url){ URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url) hObject.Open("GET",url)

Loading…
Cancel
Save