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.

calling browser function of pop up

NEWUSERNEWUSER Members
edited November -1 in Sahi - Open Source
Hi all,

I am unable to call function of a popup.

_popup("popup name"._call(Browser_function()));

Am i using right code?

Comments

  • narayannarayan Administrators
    Use _popup("popup name")._call(Browser_function());
  • apologies for incorrect syntax.
    This is what i am using: _popup("popup name")._call("NewFunction()");
    It shows me Playback success but i dont think worked. This NewFunction should perform couple of actions including showing of a alert message which is not happening.
  • narayannarayan Administrators
    Don't quote NewFunction.

    _popup("popup name")._call(NewFunction());

    If you want to use a string there, use

    _popup("popup name")._eval("NewFunction()");
  • I got the problem now. The function is not located in .js file for that page.
    When i invoke NewFunction() it opens 2nd popup which sahi is unable to recognize. so what i am trying to do is close 2nd popup by calling a function from js for 2nd popup. (does anyone have some other workaround?)
    Now the question is how can i do it? i have tried to _call(Close2ndpopup()) after putting js path in inject_top but i got no success.
  • narayannarayan Administrators
    Page 1 opens popup1
    popup1 opens popup2

    1) If popup2's window handle is available in popup1, say in variable handleToPopup2

    Use
    _popup("popup1")._call(handleToPopup2.close());

    2) If you do not have handle to popup2,

    _popup("popup1")._call(window.open("", "popup2WindowName").close());
  • I appreciate this suggestion but its not only matter of closing it. the Close2ndpopup() perform some other action before closing 2nd popup due to which my need is to call that function. So how can i call a function which is located in other JS file?
  • narayannarayan Administrators
    If you wish to call popup2's function from popup1, use

    _popup("popup1")._call(handleToPopup2.NewFunction());

    or

    _popup("popup1")._call(window.open("", "popup2WindowName"). NewFunction());

    Javascript functions are defined on the window object where the js executes, so if you have a handle to the window you can call window.functionName(parameters) to invoke the function.
  • Gr8 will let you know after trying
  • NEWUSERNEWUSER Members
    edited September 2009
    I have tried both ways as you told me but it was still giving problem.
    what i think of a reason behind that is 2nd popup is created by another js.
    so its like this: 1st popup creates a new handle which invokes a popupcreator.js which takes 2ndpopup.jsp as an argument and then creates that pop up. THe function which i want to call is in js of 2ndpopup.jsp (little bit complicated). so calling by handle is not working there.

    Code from 1st popup which creates 2ndpopup
    var Handle1 = new popupcreator("2nd Pop up", "2ndpopup.jsp?....

    and function which i want to call is in 2ndpopup.js
    so when i use _popup("popup1")._call(handle1.NewFunction()) it actually reffering to popupcreator.js(do correct me if i wrong)

    I dont think we can do much here.
  • narayannarayan Administrators
    Yes Handle1 is not the window but an instance of popupcreator. Is there some way you can figure out the window name or access the window handle?
Sign In or Register to comment.