From 5671242faff9800cf19672c738f6adf58b9af06b Mon Sep 17 00:00:00 2001 From: Yuriy Date: Thu, 25 Apr 2024 19:57:26 -0400 Subject: [PATCH] modularization and addition of Locals Specific Functions --- Locals-Functions.ahk | 50 ++++++++++++++++++++++++++++++++++++++++++ Selenium-Functions.ahk | 32 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Locals-Functions.ahk diff --git a/Locals-Functions.ahk b/Locals-Functions.ahk new file mode 100644 index 0000000..4a73062 --- /dev/null +++ b/Locals-Functions.ahk @@ -0,0 +1,50 @@ + + +; Iterate over Locals posts on the home page until found post with title +; ------------------------------------------------ +GrabLocalsPostURLUsingTitle(PostTitle){ + + Loop, 10 { + Message = Checking Post %A_index% on page for Post Titled`n%PostTitle% + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + ToolTip, %A_Index% + + ; first two items can be skipped. + ; new Post box and Create other forms of posts box + if(A_index < 3) + Continue + + ; Xpath for each post box on the main page + Xpath = //body/div/div/div/div/div/div[1]/div[%A_Index%] + + + try ElementInnerText := driver.findelementbyxpath(Xpath).Attribute("innerText") ;XPATH Inner Text + Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag + + + if(InStr(ElementInnerText, PostTitle)){ + Message = Found Post Title in Element Number: %A_index% + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + ; Pull Out the Post URL from the OuterHTML using RegEx + regexMatch := RegExMatch(ElementOuterHTML, "data-post-url=""([^""]+)""", match) + if (regexMatch) + { + PostURL := match1 + Message = URL Pulled out from OuterHTML: %PostURL% + Return PostURL + } + else { + Message = Failed to Pull out URL from OuterHTML + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + Return "Failed" + } + + } + } + + Message = Failed to find New Post in the first 10 posts + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + Return "Failed" + +} diff --git a/Selenium-Functions.ahk b/Selenium-Functions.ahk index b62ffb7..617a2c4 100644 --- a/Selenium-Functions.ahk +++ b/Selenium-Functions.ahk @@ -820,6 +820,38 @@ SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab } +GetHTMLValueFromXpathOuterHTML(XPATH, HTMLElementName){ + +Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag +; try Clipboard := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag +; Try MsgBox,,Element OuterHTML: `n, % driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag + +; Match string between quotes following the HTMLELEMENTNAME +RegexStatement = %HTMLElementName%="([^"]+)" + +; regexMatch := RegExMatch(ElementOuterHTML, "value=""([^""]+)""", match) +regexMatch := RegExMatch(ElementOuterHTML, RegexStatement, match) +if (regexMatch) +{ + ElementValue := match1 + ; Msgbox % "PostURL: " PostURL + ; Message = URL Pulled out from OuterHTML: %PostURL% + Return ElementValue +} +else { + Message = Failed to Pull out value from OuterHTML + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return "Failed" +} + +} + + + + + + + ;---\Selenium--- ;------------------------------------------------