18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

try catch cannot catch exception

herseeingherseeing Members
edited November -1 in Sahi - Open Source
os: winxp
browser: firefox 8.0
sahi build: V3.5

please see the code below:
function navigate($url){
try{
_navigateTo($url);
}catch(e){
document.execCommand('Refresh');
_alert("got it");
_logException(e);
}
}

i navigate a not existing url, even sahi threw Sahi 5xx Error, but cannot catch exception and not implemented the statements in the catch.
could you give me answer.

Comments

  • Hi herseeing,

    You cannot use the above try catch method as once you are navigationg to non existing url , the error 5xx error is been thrown by the server and not by Sahi.

    You can use something like this:
    _navigateTo("http://sahi.co.in/demo/training.htm");
         try{
        _click(_link("Link Test"));
    }catch(e){
      _logException(e);
      _alert("URL is different");
    }
    

    Using _logExceptionAsFailure:
    _navigateTo("http://sahi.co.in/demo/training.htm");
                     try{
        _click(_link("Link Test"));
    }catch(e){
      _logExceptionAsFailure(e);//Logs the exception, and fails, 
       // and in the logs, points to the original line as source of failure.
      _alert("URL is different");
    }
    

    Regards
    Sumitra
  • thank you, Sumitra.
    I am clear now, but i just want to try navigateTo, is there any possibility?
  • Hi herseeing,

    1. Are you unable to open your application for any reason? Is sahi timing out?

    2. If it is timing out, you can add a _wait on a condition .

    Here is an example:

    _wait(1000); // Will stop execution for a second
    _wait(1000, _byId("ajaxy").innerHTML!="");// Will wait till div by id “ajaxy” is populated
    // or one second, whichever occurs sooner

    Regards
    Sumitra
  • actually, my problem is that sahi sometimes hang with a blank page when navigateTo a page,
    I read through the forum, but cannot find good idea.
  • Hi herseeing,

    Kindly have a look at the below link:

    http://sahi.co.in/w/trouble-shooting-sahi

    Also, check if you are facing this problem on all the browser.

    Let me know if this solves your issue.

    Regards
    Sumitra
Sign In or Register to comment.