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.

Exception is displayed even when control exists

lalwaniajaylalwaniajay Members
edited November -1 in Sahi - Open Source
Hi,
I am using the following script to fill in a text box, press enter(return) key and then find a link on the resulting page.

_setValue(_textbox(1),"Some Text");
_keyPress(_textbox(1),13);
_isVisible(_link("More"));

On executing the code using the controller, false is returned even when the link is present, executing the same code from that page results in appropriate results.

I am facing the same problem when i use sahi java api. I get a NullPointerException.
Any workarounds ?

Comments

  • narayannarayan Administrators
    The Controller's evaluate expression is not the same as a script. The Evaluate Expression just executes javascript on the browser. It will not wait between steps or wait for page load etc.
    Use the "Evaluate Expression" box to execute individual steps rather than multiple steps.


    In your code snippet, you should be asserting for isVisible.
    _setValue(_textbox(1),"Some Text");
    _keyPress(_textbox(1),13);
    _assert(_isVisible(_link("More")));
    

    "I am facing the same problem when i use sahi java api. I get a NullPointerException."

    Please elaborate with code.

    Regards,
    Narayan
  • I got a workaround to that.. I used _wait(5000) before asserting. So the playback mode on the controller works fine.
    But using that in my java code:
    browser.wait(5000) or even browser.execute("_sahi._wait('5000')")

    sahi does not wait. but immediately exits with failed assertion.


    Ref : "I am facing the same problem when i use sahi java api. I get a NullPointerException."

    The Java code that I am using is:

    browser.textbox(1).setValue("Some Text");
    browser.execute("_sahi._keyPress("+browser.textbox(1)+",13);");
    assertTrue(browser.link(More).isVisible());


    The exception on the third line is:
    java.lang.NullPointerException
    at WebBPAInterfaces.Home.FavouriteInterface.markAsFavourite(FavouriteInterface.java:17)
    at WebBPAInterfaces.Home.FavouriteInterface.markAsFavourite(FavouriteInterface.java:46)
    at WebBPAInterfaces.Home.ArchiveInterface.prepareArchiveProcess(ArchiveInterface.java:53)
    at WebBPATests.ProcessModel.ArchiveProcessModel_tp.init(ArchiveProcessModel_tp.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:103)
    at org.testng.TestRunner.runWorkers(TestRunner.java:689)
    at org.testng.TestRunner.privateRun(TestRunner.java:566)
    at org.testng.TestRunner.run(TestRunner.java:466)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
    at org.testng.SuiteRunner.run(SuiteRunner.java:191)
    at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
    at org.testng.TestNG.run(TestNG.java:701)
    at org.testng.TestNG.privateMain(TestNG.java:840)
    at org.testng.TestNG.main(TestNG.java:818)
  • Using Thread.sleep(5000) also does not help. Assertion fails.
  • narayannarayan Administrators
    The wait method is actually

    browser.waitFor(5000)

    You are using Object.wait which is not what we want.

    I am not sure why it is failing. Is the page loaded properly for the assertion to be true? Is the page loading slowly?

    Regards,
    Narayan
  • Hi Narayan,

    The page loads properly, everything is fine. And now the code runs fine.
    Thanks for the help.

    Regards,
    Ajay
This discussion has been closed.