Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago

Click outside a modal dialogue

Hello,

I'm working on writing scripts for handling a Modal dialogue in an AngularJS app.

When the modal is open and I click anywhere outside the modal, it gets closed.

 

I'm not able to replicate this behavior in my javascript code. How to click on the page outside the modal dialogue? any pointers would be helpful. 

 

Thank you

Abhi

 

7 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Abhi,

     

    Just get a reference to some object on the page that does not belong to the modal window and is not overlapped by it and click this object. Does this work?

    Also, modal windows usually have some control to close them. Depending on your needs you may click such control for your window.

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Hey Alex, Well, when the modal dialogue opens(as any other dialogue), the whole background looks disabled, so object recognition doesn't work. There are buttons on the modal using which I can close it, but what I'm trying is different. Closing outside the modal dialogue would also make the dialogue disappear. The solution suggested by Yuri seems to work(Esc), but I'm wondering if (Esc) and clicking outside the Modal means the same.

       

      Thank you

      Abhi 

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi Abhi,

         

        > I'm wondering if (Esc) and clicking outside the Modal means the same.

        I think that this is the question to your developers as the answer may depend on the implementation.

         

        > [...] the whole background looks disabled, so object recognition doesn't work.

        But you can switch to the Object Browser  in TestComplete and check for the objects on the page.

  • YuriPeshekhonov's avatar
    YuriPeshekhonov
    SmartBear Alumni (Retired)

    Hi Abhi,

     

    I agree with Alex. Just wanted to add something - you can simulate a keystroke (e.g. "Esc") using the Keys method, if your modal dialog can be closed using the keyboard. 

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thank you, Yuri! Esc works well. I'm wondering if Esc and clicking outside the modal would mean the same? The test I'm trying to do it that when I type in some text on the modal and click outside of the modal, it disappears and the text wouldn't be saved. 

       

      Thank you

      Abhi