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.

Only execute command if variable is not empty

abourneabourne Members
edited November -1 in Sahi - Open Source
Hi,

I am using the following function and only want to execute the command if the variable contains data, however when using this function it is blanking out the value even though the variable contains data

Any assistance will be much appreciated

Thanks

Andrew

function set_TypeProcessingCode($TypeProcessingCode)
{
if ($TypeProcessingCode != "") _setSelected(_select("212"), $TypeProcessingCode);
}

Comments

  • Hi Andrew
    Try this i hope it's work

    function set_TypeProcessingCode($TypeProcessingCode)
    {
    if ($TypeProcessingCode.length != 0) _setSelected(_select("212"), $TypeProcessingCode);
    }
  • abourneabourne Members
    Hi chaudharyparesh,

    Thank you for the quick response. I tried this but still have the issue. I think the issue is when I have the if statement on one line. If I rewrite it as follows then it works

    function set_TypeProcessingCode($Template, $TypeProcessingCode)
    {
    if ($TypeProcessingCode.length != 0)
    {
    _setSelected(_select("212"), $TypeProcessingCode);
    }
    }
  • narayannarayan Administrators
    Hi abourne,

    Yes, your observation is correct. Statements which perform actions on the browser need to be on a line of their own.
    This is because Sahi scripts are first parsed and the parser is not very sophisticated right now.

    Regards,
    Narayan
Sign In or Register to comment.