Jump to content
UBot Underground

Anyway To Exit A Loop Immediately?


Recommended Posts

I have many embedded loops to check for multiple possible errors. In each of those loops there are If/Then to detect which possible error it encountered and how to recover from that. To which the last part of the "then" needs to be stop executing this loop and go back to the last step. I see no way to do this in ubot. Other scripting apps I've used have commands like "Exit Loop" or "End Loop" to stop processing the rest of the loop.

If there are 10 possible errors and I find the error on the first try, why even try the other 9 and waste all that time?

The below is basically how it goes with most of the actual code removed and there are many more embedded loops  and if/thens to handle more possible errors, this just illustrated what I'm trying to accomplish.

Could the below be greatly simplified by making each "loop" its own subroutine/function? if so how is that done in Ubot?

 

Structure is like this:

 

set(#MainLoop,0,"Global")

Loop while(#MainLoop = 0) {

     ---login to site code here---

     set(#PageLoad,0,"Global")

     Loop while(#PageLoad = 0) {

           If error found

                then

                      ---clean up routine here---

                      set(#PageLoad,1,"Global")

           if error2 found

                then

                      ---clean up routine here---

                      set(#PageLoad,1,"Global")

     }

     set(#PageLoad,0,"Global") ---make sure the variable is reset before next loop---

    ---If we made it this far the page loaded correctly---

     ---wait for element on page ---

     ---Click save file button on page---

     save downloaded file(#filename)

     set(#FileSave,0,"Global")

     loop while(#FileSave,0,"Global"){

            set(#ButtonState,$scrape attribute(<id="export">,"outerhtml"),"Global")
            if($find index(#ButtonState,"data-style=\" data-loading=\"\">") < 0) {
                then {
                    ---text not found so ButtonState changed and file is ready to save---
                    if($file exists(#filename)) { ---checks to make sure the file from the above save actually got saved---
                        then {
                            comment("ADD DATA VERIFY CHECK HERE")
                            set(#FileSave,1,"Global")
                        }
                        else { ---Button state changed but file never got saved, what happened?---
                            set(#ErrorSeen,$scrape attribute(<class="error"),"Global")
                            if(#ErrorSeen = "There was a problem exporting your data") {
                                then { ---Reset Browser and load login page from table again---
                                    reset browser
                                    wait(5)
                                    ---NEEDS TO STOP LOOKING FURTHER HERE---
                                    ---Exit FileSave loop so it can process main loop again--
                                }
                                else {
                                }
                            }
                            set(#ErrorSeen,$scrape attribute($element offset(<tagname="h1">,0),"innertext"),"Global")
                            if(#ErrorSeen = "Log in") { 
                                then {---Login page re-appeared so session timed out---
                                    ---NEEDS TO STOP LOOKING FURTHER HERE---
                                    ---Exit FileSave loop so it can process main loop again--
                                }
                                else {
                                }
                            }
                            set(#ErrorSeen,$url,"Global")
                            if(#ErrorSeen = "https://www.site.com/error"){
                                then {---We ended up on custom error page try again---
                                    reset browser
                                    wait(5)
                                    ---NEEDS TO STOP LOOKING FURTHER HERE---
                                    ---Exit FileSave loop so it can process main loop again--
                                }
                                else {
                                }
                            }
                        }
                    }
                }
                else {---the button state is still greyed out which means data is loading still---
                    wait(7)---Wait 7 sec, loop back to beginning of FileSave loop---
                }
            }

      }

---We got here file must have saved correctly and passed verification---

increment(#LoginCount) ---Move to next record in table---

if($table cell(&Login,#LoginCount,0) = "") { ---Check to see if we've reached the end of the table---
     then {---we've process all records in table, clean up and move on to rest of the script---
           reset browser
           wait(5)
           set(#MainLoop,1,"Global")
     }
     else {---set variables for next cycle of MainLoop---
           set(#filename,"C:\\temp{$table cell(&Login,#LoginCount,2)}.csv","Global")
           set(#FileSave,0,"Global")
      }
}

}

---rest of script---

Link to post
Share on other sites

You can try using JavaScript nested as child loops and check for X on page.

 

run javascript command and $eval to return values.

 

 

Same with jquery. Just run minified jquery in run javascript commnand and return values with $eval

 

Regards,

CD

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...