18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
If statements
I have a web form that has multiple iterations, some with different fields than others. To save time while testing, I would like to make one script that will fill out whatever form I bring up. To do so, I am trying to use an If statement in conjunction with assertexists as follows:
if (_assertExists(_textbox("username") == true)){
_setValue(_textbox("username"), "Test123");
}
This way if the textbox is present, it will fill it in otherwise skip to the next. However it tries to fill it in anyway and fails when its not there. Any help would be greatly appreciated.
Thanks,
Sahi Newbie
if (_assertExists(_textbox("username") == true)){
_setValue(_textbox("username"), "Test123");
}
This way if the textbox is present, it will fill it in otherwise skip to the next. However it tries to fill it in anyway and fails when its not there. Any help would be greatly appreciated.
Thanks,
Sahi Newbie
Best Answer
-
Hi Noomrise,
asserts don't work for if-statements, but you could try
if(_isVisible(_textbox("username"))){
_setValue(_textbox("username"), "Test123");
}
Answers
ReferenceError: "_isvisible" is not defined. (C:\Users\Mike\sahi_pro\userdata\scripts\PageFill.sah#5)
Below is the script:
if (_isVisible(_textbox("username")))
{
_setValue(_textbox("username"), "Test123");
}
if (_isVisible(_textbox("password")))
{
_setValue(_textbox("password"), "Test123");
}
if (_isVisible(_textbox("x-billnamefirst")))
{
_setValue(_textbox("x-billnamefirst"), "First");
}
if (_isVisible(_textbox("x-billnamelast")))
{
_setValue(_textbox("x-billnamelast"), "Last");
}
if (_isVisible(_textbox("x-billemail")))
{
_setValue(_textbox("x-billemail"), "mail@mail.com");
}
if (_isVisible(_textbox("x-billaddr")))
{
_setValue(_textbox("x-billaddr"), "1234 Main Street");
}
if (_isVisible(_textbox("x-billcity")))
{
_setValue(_textbox("x-billcity"), "springs");
}
if (_isVisible(_textbox("x-billstate")))
{
_setSelected(_select("x-billstate"), "Alabama");
}
if (_isVisible(_textbox("x-billzip")))
{
_setValue(_textbox("x-billzip"), "12345");
}
if (_isVisible(_textbox("x-acc1")))
{
_setValue(_textbox("x-acc1"), "4444333322221111");
}
if (_isVisible(_select("x-ccexpmonth")))
{
_setSelected(_select("x-ccexpmonth"), "01");
}
if (_isVisible(_select("x-ccexpyear")))
{
_setSelected(_select("x-ccexpYear"), "2016");
}
if (_isVisible(_textbox("x-sec1")))
{
_setValue(_textbox("x-sec1"), "123");
}