updated Subscribestar posting to use javascript instead of xpath, added extra error logging

main
Yuriy 1 year ago
parent 57ab61167b
commit c4eef942e5

@ -42,7 +42,7 @@ global UpdateVersionNumber
ScriptName = Freedomain Social Media Poster ScriptName = Freedomain Social Media Poster
ScriptVersion = 2.83 ScriptVersion = 2.84
FullScriptName := ScriptName . " " . ScriptVersion FullScriptName := ScriptName . " " . ScriptVersion
;---ToDo--- ;---ToDo---

@ -61,7 +61,29 @@ if(InStr(LoginStatus, "Log In")){ ; need to log in
Message = Inputting Post Message = Inputting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; Click on "Start your post by clicking here" ; click the "Create Post" button
js = document.querySelector("div[class='new_post'] div[class='flat_button for-new_post']").click(); ; Send content through javascript (Great for getting around emoji chrome limitaitons)
try, driver.executeScript(js)
sleep, 1000
; post button at bottom right corner
Selector = ".flat_button.for-post_form"
; check if post button exists
js = return document.querySelector(%Selector%).innerText
try, Status := driver.executeScript(js)
if(!Status){
Message = Post Failed. Failed to click on "Create Post" button
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
/*; Click on "Start your post by clicking here"
Xpath = //div[contains(text(),'Create Post')] Xpath = //div[contains(text(),'Create Post')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000) Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){ if(Status){
@ -84,6 +106,7 @@ if(Status){
} }
} }
} }
*/
; sleep, 5000 ; sleep, 5000
; msgbox ; msgbox
@ -102,33 +125,31 @@ if(Status){
; Input Text into pop-up edit box ; Input Text into pop-up edit box
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //trix-editor[@role='textbox'] SubscribeStarJSDescription := FormatTextToJSText(PostTitleAndBody)
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody) js = document.querySelector("trix-editor[role='textbox']").value = "%SubscribeStarJSDescription%";
if(Status){ try driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons.
Message = Failed to Input Post using Direct Xpath. Trying with Relative catch e {
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") Message = Failed to Input Post Contents (E#8281)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Xpath = /html/body/div/div[3]/div[2]/div[2]/div/div[1]/form/div[2]/div[1]/trix-editor SaveDriverURLOFErrorPage()
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody) Return
if(Status){ }
Message = Failed to Input Post using Relative Xpath. Trying with Javascript
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SubscribeStarJSDescription := FormatTextToJSText(PostTitleAndBody) ; check if value was input
js = document.querySelector("trix-editor[role='textbox']").value = "%SubscribeStarJSDescription%"; js = return document.querySelector("trix-editor[role='textbox']").innerText
try driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons. try, Status := driver.executeScript(js)
catch e { if(!Status){
Message = Failed to Input Post Contents (E#8281) Message = Failed to input Post Content (E#8282)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage() Return
Return }
} else, { ; if input successfully, post to error log
; msgbox, 3 String := SubStr(Status, 1, 30)
} Message = Post Content that got input: %String% ...
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
}
; Attach an image if a filepath was provided ; Attach an image if a filepath was provided
if(ImageAttachmentFilepath != ""){ if(ImageAttachmentFilepath != ""){
@ -163,7 +184,42 @@ if(ImageAttachmentFilepath != ""){
; Click the post Button ; Click the post Button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //button[contains(text(),'Post')]
; post button at bottom right corner
Selector = ".flat_button.for-post_form"
; check if post button exists
js = return document.querySelector(%Selector%).innerText
try, Status := driver.executeScript(js)
if(!Status){
Message = Post Failed. Unable to find Post button using usual method.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
; Msgbox % "Status: " Status
js = document.querySelector(%Selector%).click()
try, Status := driver.executeScript(js)
; Msgbox % "Status: " Status
sleep, 2000
; check if post button still exists
js = return document.querySelector(%Selector%).innerText
try, Status := driver.executeScript(js)
if(Status){
Message = Post Failed. Failed to click Post button using usual method.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
/* Xpath = //button[contains(text(),'Post')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000) Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){ if(Status){
Message = Failed to Submit Post Message = Failed to Submit Post
@ -172,6 +228,7 @@ if(ImageAttachmentFilepath != ""){
Return Return
} }
*/
IniWrite, Successful, %StatusFileFilePath%, Status, SubScribeStar IniWrite, Successful, %StatusFileFilePath%, Status, SubScribeStar
AddToTotalPostsPostedCount() AddToTotalPostsPostedCount()

Loading…
Cancel
Save