Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

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

Best Answer

Answers

  • Thanks Sahir, that seemed to work with only 2 fields, one present and one not. However, when I added all the possible fields from all the possible pages I might run in to, it fails with the following error.

    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");
    }
  • for DOM related things you have to use _condition like
    if (_condition(_isVisible(_textbox("x-sec1")))) {
      // do stuff
    }
    
Sign In or Register to comment.