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.

Need help with if() statements

stevenlongstevenlong Members
edited November -1 in Sahi - Open Source
Hi all

I'm struggling to get an if statement to work in Sahi.

the following _alert() shows "true":
_alert(_containsText(_row(_table(0), 16), "SKU:"));
However, when trying to use that in an if():
if(_containsText(_row(_table(0), 16), "SKU:")) {
    _alert("hello");
}
I get an error on the logs saying, "TypeError: 'rows' is null or not an object No trace available".

And if I use the _condition() function:
if(_condition(_containsText(_row(_table(0), 16), "SKU:"))) {
    _alert("hello");
}
it fails silently.

Any ideas what I'm doing wrong, and how I can get it to evaluate the condition in the way that I want?

Thanks.

Comments

  • I'm having the same problem!

    _containsHTML doesn't work also!

    The proxy says org.mozilla.javascript.EcmaError: TypeError: Cannot find function _containsText. (<cmd>#2)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3232)
    at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3244)
    at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3304)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:1988)
    at org.mozilla.javascript.gen.c40._c0(<cmd>:2)
    at org.mozilla.javascript.gen.c40.call(<cmd>)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
    at org.mozilla.javascript.gen.c40.call(<cmd>)
    at org.mozilla.javascript.gen.c40.exec(<cmd>)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1144)
    at net.sf.sahi.rhino.ScriptRunner.run(ScriptRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
  • Hi there!

    I think that I've figured out the problem:

    It's all about the scripting changes introduced in v2 of SAHI. According to the SAHI documentation (scripting-changes-in-sahi-v2) any function that requires access to the DOM must be enclosed between a <browser> element, "otherwise they will be executed on the proxy and will fail because they do not have access to the browser
Sign In or Register to comment.