No internet connection
  1. Home
  2. How to

Automatically click OK on unnamed dialogs

By Marek Bert Fuchs @bert
    2023-11-20 11:14:15.841Z

    Hello,

    how do force SF to automatically close (hit ok) these types of dialogs, which sometimes appear during script running?

    Thank you!

    M. Bert F.

    Solved in post #3, click to view
    • 4 replies
    1. Marek Bert Fuchs @bert
        2023-11-20 13:34:46.985Z

        I figured it out.

        // Wait for confirmation dialog
        const confWin = sf.ui.proTools.confirmationDialog
        const isThereAConfWin = confWin.elementWaitFor({
            timeout: 500,
            onError: "Continue"
        }).success
        
        // Accept confirmation dialog
        if (confWin) {
            sf.ui.proTools.windows.first.buttons.whoseTitle.is("OK").first.elementClick();
        };
        

        Helping source: Stop script upon cancel....how? #post-2

        1. That looks almost perfect.

          Your if block is testing something that always will be true though, which means it'll try to run the elementClick action even if the confirmationDialog wasn't found.

          Your if block should instead be:

          // Wait for confirmation dialog
          const confWin = sf.ui.proTools.confirmationDialog
          const isThereAConfWin = confWin.elementWaitFor({
              timeout: 500,
              onError: "Continue"
          }).success
          
          // Accept confirmation dialog
          if (isThereAConfWin) {
              sf.ui.proTools.windows.first.buttons.whoseTitle.is("OK").first.elementClick();
          };
          

          Or:

          // Wait for confirmation dialog
          const confWin = sf.ui.proTools.confirmationDialog;
          const elementWaitResult = confWin.elementWaitFor({
              timeout: 500,
              onError: "Continue"
          });
          
          // Accept confirmation dialog
          if (elementWaitResult.success) {
              elementWaitResult.element.buttons.whoseTitle.is("OK").first.elementClick();
          };
          

          Or:

          // Wait for confirmation dialog
          const confWin = sf.ui.proTools.confirmationDialog;
          const elementWaitResult = confWin.elementWaitFor({
              timeout: 500,
              onError: "Continue",
          });
          
          // Accept confirmation dialog
          if (confWin.exists) {
              confWin.buttons.whoseTitle.is("OK").first.elementClick();
          };
          
          
          Reply1 LikeSolution
          1. Marek Bert Fuchs @bert
              2023-11-20 18:31:41.193Z

              Thank you! My goal is to have the most possible short code and fast script results. Which one would be the fastest?

              1. #2 or #3 would be ever so slightly faster, since they forego querying the UI a 2nd time. My personal preference would the #3 (I'm counting the 3 replies/examples I shared), because it's easier to read/reason about, which is important.
                Generally speaking, all of this would be so fast that you're unlikely to see any actual performance differences in real-world scenarios.