No internet connection
  1. Home
  2. How to

How to extend time waiting for an element to appear

By Andrew Sherman @Andrew_Sherman
    2021-05-09 05:35:37.341Z

    I'm using "wait for an UI element to appear" in a certain script, but it takes a while for the app to load initially and the script fails after a while.

    "Element was not found or removed after waiting 2000 ms"

    How do I make it wait in a loop until the condition is satisfied?

    sf.ui.app("pro.writer.mac").mainWindow.children.whoseRole.is("AXToolbar").first.elementWaitFor();
    
    • 1 replies
    1. Hi Andrew,

      Use the timeout parameter, here waiting 10 seconds (10,000 milliseconds):

      sf.ui.app("pro.writer.mac").mainWindow.children.whoseRole.is("AXToolbar").first.elementWaitFor({
          timeout: 10000,
      });
      

      If you set it to -1 it will wait indefinitely, but we don't necessarily recommend that, at least not in packages you publish, as that would never catch a problem/error in the external app causing the element to actually never appear, and would cause your SF to be stuck forever until somebody presses Ctrl+Shift+Esc to stop all running commands.