From c6cf2a408a2b7d08c400ac71ebbcdb395959c4f0 Mon Sep 17 00:00:00 2001 From: yuriy Date: Sun, 30 Jul 2023 22:14:41 -0400 Subject: [PATCH 1/5] added function to send text to xpath element letter-by-letter --- Selenium-Functions.ahk | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Selenium-Functions.ahk b/Selenium-Functions.ahk index faa681d..dbf3e5d 100644 --- a/Selenium-Functions.ahk +++ b/Selenium-Functions.ahk @@ -773,6 +773,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 try URLOfLastErrorPage := driver.URL } From 84c64bd4282f8a675a323bfb7bf41480bb1e4e1c Mon Sep 17 00:00:00 2001 From: yuriy Date: Sun, 20 Aug 2023 00:36:38 -0400 Subject: [PATCH 2/5] removed discord messages for repetative messages so errorlog is easier to read --- Selenium-Functions.ahk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Selenium-Functions.ahk b/Selenium-Functions.ahk index dbf3e5d..ff761d2 100644 --- a/Selenium-Functions.ahk +++ b/Selenium-Functions.ahk @@ -183,12 +183,12 @@ CheckCurrentTabForCurrentSite(){ if(!InStr(CurrentTabURL, CurrentSite)){ 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" } else, { Message = CheckCurrentTabForCurrentSite() passed successfully - SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") + SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile") } } /* @@ -394,12 +394,12 @@ ActivateChromeTab(URL){ if(A_index < 3){ if(CurrentTabURL = StartingTabURL){ 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() } else, { 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){ @@ -429,7 +429,7 @@ ActivateChromeTab(URL){ ; / loop through 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" } @@ -438,7 +438,7 @@ ActivateChromeTab(URL){ CheckForAlerts(){ Message = Checking for Any Obstructing Alerts in Chrome - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") status := 1 try driver.SwitchToAlert() @@ -450,7 +450,7 @@ CheckForAlerts(){ if(status){ ; msgbox, alert found ; 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") try driver.switchToalert().accept() ; try driver.switchToalert().dismiss() From ed887d50455652489e355b5a10a0656b30e8c45b Mon Sep 17 00:00:00 2001 From: yuriy Date: Sun, 20 Aug 2023 00:42:10 -0400 Subject: [PATCH 3/5] updated error message on selenium no connect --- Selenium-Functions.ahk | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Selenium-Functions.ahk b/Selenium-Functions.ahk index ff761d2..1b0d5fb 100644 --- a/Selenium-Functions.ahk +++ b/Selenium-Functions.ahk @@ -5,8 +5,6 @@ ShowSeleniumErrorMsgbox(){ - ; Clipboard := ChromeVersion - ; Msgbox % "Chromeversion: " Chromeversion IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% ; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion ; msgbox, failed to connect to Chrome for some reason. @@ -14,27 +12,23 @@ ShowSeleniumErrorMsgbox(){ ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") 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, "") IfMsgBox Yes, { ; Reload script Reload - } Else IfMsgBox No, { - run, https://chromedriver.chromium.org/downloads - ExitApp - ; open chromedriver site - } Else IfMsgBox Cancel, { - URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation - run, %url% - } - ExitApp - + } + Else IfMsgBox No, { + run, https://chromedriver.chromium.org/downloads + ExitApp + ; open chromedriver site + } Else IfMsgBox Cancel, { + URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation + run, %url% } - -/* -*/ - + ExitApp +} ; -------------------------------Tab Navigation & Activation------------------------------- From 324d5a177a95f8112da9a7616411fa67dba4b64a Mon Sep 17 00:00:00 2001 From: yuriy Date: Sun, 20 Aug 2023 00:48:05 -0400 Subject: [PATCH 4/5] code cleanup --- URLDownloadToVar.ahk | 55 -------------------------------------------- 1 file changed, 55 deletions(-) diff --git a/URLDownloadToVar.ahk b/URLDownloadToVar.ahk index 2c9cc4b..3871921 100644 --- a/URLDownloadToVar.ahk +++ b/URLDownloadToVar.ahk @@ -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){ hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") hObject.Open("GET",url) From 7afb2274a2f86b09024266ac5e80816886fbb720 Mon Sep 17 00:00:00 2001 From: yuriy Date: Sun, 20 Aug 2023 01:20:16 -0400 Subject: [PATCH 5/5] added function to get latest stable chrome version, function to get URLs for chrome and chromedriver for that given version --- Chrome-Functions.ahk | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Chrome-Functions.ahk b/Chrome-Functions.ahk index 5b1c26e..0b73a39 100644 --- a/Chrome-Functions.ahk +++ b/Chrome-Functions.ahk @@ -59,7 +59,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 json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json") @@ -84,22 +105,25 @@ GetURLofLatestChromedriver(ChromeVersion){ 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() { - ; 64 bit version if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64") 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 } } - ; Msgbox % "chromedriverDLURL32: " chromedriverDLURL32 - ; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64 - return chromedriverDLURL32 + URLS = %chromeDLURL64%||%chromedriverDLURL64% + return URLS } \ No newline at end of file