Exception Handling (try catch) anyone?

Hi all,
I have to deal with error now…how can we implement error handling…?

For ex, login credentials

Open website …

  • enter user
  • enter password
  • submit login

1.If suppose in the above we accidently put wrong password, username or the internet gets slow, so right now it just stops the bot from running… how can we deal with this.?

2.I want the error handling for all the condition so if any kind of error occurs at any step, it just refresh the page & re enters all the value again… right now I tried repeat & retry function they don’t run unlimitedly they have fixed no. of times, my bot is working 24x7 so I want that :confused: @ashapkina @Bonnero @timriewe

Hi @DesertEagle
You could use a while loop that checks for an “error” variable combined with exception handling. Something like this:

Set “error”=0
While “error”=0
Try to complete
Set user name
Set password
Submit
Set “error”=1
If an exception occurred
Set “error”=0

1.Hey, I have done it like this while inspects the element of the next page as long as it doesn’t get that xpath it keeps looping …this is working fine …

  1. Problem is with the internet connection drop, if i remove the lan cable or disconnect net then page shows no internet connect error & the website doesnt open. I want this technique to work with this now maybe something like it keeps re opening the webbrowser & whenever it shows no internet error it re open browser again…

Thanks please do reply boss …you are good !!

Why do you want to reopen browser if the connection is lost? Without connection the process won’t work so why keep trying?

so whenever the internet is re connected it continues logging in … as the bot is always running thats why

Then you can use the structure I proposed above. That would try indefinitely until the “error” variable is set to 1. However, I would recommend limiting the number of intents so after 100 trials or so the bot could send an alert to a user to check what’s wrong and plug in the network cable for example :wink:

1 Like

Hi, can you please check if thats how you meant? cuz i dont know why this is also working …just confim if i’m wrong plz correct me

Exactly! That’s what I meant :+1:

Cheers bruv…you are the best …but one thing now I’m not able to get out of this while… I have to proceed further with my website bill filling & excel reading writing as you can see

Please check …

Sorry, I don’t understand your question.

Well your method worked for the login perfectly, but after the login that’s where I’m stuck now as it keeps looping the login only… I’m unable to go futher before I was able to read the data from excel & paste it on the website that’s my second step … I want to get out of while once the internet is plugged in

this is what i meant …my program is not going into this while steps :confused:

The way you had it before it should work. Both while loops should be on the same level. In this last one you nested the second one inside the first one. The way you put it now it only goes into the second while loop if an exception occurred.

got it, thanks :slight_smile: your method is working fine …it was my xpath while condition which was stopping it …i unticked it …now with your method it works well :slight_smile: I owe you a beer.

One last question, going further after login in …same exception technique is applied? as I will be reading excel & pasting data & sending email to clients now …cant we define exception at 1 area only & covers up the entire project …or we have to apply it everywhere on different steps.?

I would recommend using exception handling depending on what kind of exception you would expect. If the network is down you want the robot to react differently than when a webpage is not available or an xpath cannot be found. So you can put an exception handling around each group of actions (login, scrap web data, update excel) to catch the exceptions that might occur and react accordingly.
(Beer noted :smiley:)

2 Likes

haha great work mate, you have been such a big help :stuck_out_tongue:

hope, my project also helped you in someway… just a 24 x 7 bot with a lot of steps involved i guess :wink:

I am glad it helped :+1:

1 Like