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.

How to check if form exist?

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

I am trying to check if a form exist.
I use, _exists(document.forms[id]))
When i evaluate this in the controller, it returns true.
I also combined with DOM relations, _exists(document.forms[id], _in(_div(id))) and it also returns true.

But when i run it in playback, form element is null already.
--Log--
_sahi.setServerVar('___lastValue___1333420826058', _exists(null)); [1266 ms]
_sahi.setServerVar('___lastValue___1333421619813', _exists(null, _in(_div("calcContentSlide")))); [1286 ms]


Please advise guys.

Thanks,
lonely_girl

Comments

  • smrithismrithi Members
    edited April 2012
    Hi lonely_girl,

    Could you please Ctrl+Hover on the form and use the same to check if it exists?

    Have a look at:

    http://sahi.co.in/w/all-apis

    Also, kindly use the above API in the script and check if this solves your issue.

    Regards
    Smrithi
  • smrithi wrote:
    Hi lonely_girl,

    Could you please Ctrl+Hover on the form and use the same to check if it exists?

    Have a look at:

    http://sahi.co.in/w/all-apis

    Also, kindly use the above API in the script and check if this solves your issue.

    Regards
    Smrithi

    Hi smrithi,

    Thanks for the reply.
    But Ctrl + Hover doesn't read the form as an accessor. It just returns the elements/accessors inside my form (i.e _select, _div, _list, _listItem)
    I've also checked the above but didn't find a form accessor (i.e. _form).
  • Hi lonely_girl,

    Install the firefox addon Firebug and use the inspect option available in it to get the exact id of the form. The form may be in div or table tag. Assuming the form is in the table tag you can use

    _assertExists(_table("/idIOfTable/"));

    or you can check if the different elements in the form exist individually by

    if(_exists(_table("/idIOfTable/")))
    {
    _assertExists(_textbox("/textboxId/", _in(_table("/idIOfTable/"))));
    _assertExists(_password("/passwordboxId/", _in(_table("/idIOfTable/"))));
    _assertExists(_radio("/radiobuttonId/", _in(_table("/idIOfTable/"))));
    _assertExists(_checkbox("/checkboxid/", _in(_table("/idIOfTable/"))));
    _assertExists(_select("/dropdownId/", _in(_table("/idIOfTable/"))));
    _assertExists(_submit("/buttonId/", _in(_table("/idIOfTable/"))));
    }
    else
    {
    _log("The table 'idIOfTable' not found on the page", "failure");
    }
Sign In or Register to comment.