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 a popup exists?

rj412rj412 Members
edited November -1 in Sahi - Open Source
I tried with both _isVisible and _exists, both failing with Window/Domain not found.

var $condn;
_popup("Page 2")._set($condn, _exists(_popup("Page 3")._image("Image.gif")));
if ($condn) {
PageExistDoSomething();
} else {
PageDoesNotExistDoSomethingElse();
}


var $condn;
_popup("Page 2")._set($condn, _isVisible(_popup("Page 3")._image("Image.gif")));
if ($condn) {
PageExistDoSomething();
} else {
PageDoesNotExistDoSomethingElse();
}

Comments

  • narayannarayan Administrators
    Hi rj412,

    Is there a reason why it uses both "Page 2" and "Page 3"?

    The right way to do it is like this:
    var $condn;
    _popup("Page 2")._set($condn, _exists(_image("Image.gif")));
    // Note that we have removed the _popup prefix before _exists. 
    if ($condn) {
      PageExistDoSomething();
    } else {
      PageDoesNotExistDoSomethingElse();
    }
    


    _popup is a marker to execute a particular piece of code on another window. It is to be used only at the start of the command. We are trying to simplify this and make it more intuitive, but currently, you need to use _popup only at the start of the command.

    Regards,
    Narayan
  • our application uses a portal that launches the apps by launching multiple popup windows.

    By not having it as prefix as well as condition check, Sahi is confused as to which window to look for.
    From the Portal, I launch 'App2-Page2' , it then automatically launches 'App3-Page3' popup.
    So at this point, I need to do a _isVisible or _exists of an image of 'App3-Page3', if it does not exists, I need to force it to launch...see code below.


    /* ---- Code
    */
    launchFromPortal (App2-Page2-Link);

    Perform_App2-Page2_operations ();
    //At this point App2-Page2 will automatically launch App3-Page3 due to some other condition

    var $condn;
    _popup("App2-Page2")._set($condn, _exists(_popup("App3-Page3)._image("Image.gif")));

    if ($condn) {
    App3-Page3_AutomaticLaunch_WORKED();
    } else {
    App3-Page3_AutomaticLaunch_FAILED();
    App3-Page3_ForceLaunch_INSTEAD();
    }


    I hope this helps.
    Thanks,
    RJ
Sign In or Register to comment.