Scripted browser Runtime 100x

Hello guys, Currently, I´m updating my scripts to the new runtime of synthetics, Althought, I got stuck in two questions, the first one is, how does the waitForAndFind works now ?. since it has been depreceated, and, when I try to click in a button, I always receive the error message “stale element reference: element is not attached to the page document” Could you help me please.
Below, I have the code I´ve been working.


  .then(function () {
    return Promise.resolve(true)

      .then(function () {
        return (
          logger.log(1, "Open URL https://www.cockpit.com.ar", "Check_Url"),
          $webDriver.get(web).then((e) => e)
        );
      })
      .then(function () {
        return (
          logger.log(2, "Insert the e-mail"),
          $webDriver
            .findElement($selenium.By.id("Email"), DefaultTimeout)
            .then((e) => (e.sendKeys($secure.LOGIN_ARG2), Promise.resolve(!0)))
        );
      })
      .then(function () {
        return (
          logger.log(3, "Insert the password"),
          $webDriver
            .findElement($selenium.By.id("Senha"), DefaultTimeout)
            .then(
              (e) => (
                e.sendKeys($secure.COCKPIT_ARGENTINA), Promise.resolve(!0)
              )
            )
        );
      })

      .then(function () {
        return (
          logger.log(4, '("Clica na opção Jetta")'),
          $webDriver
            .wait(
              $selenium.until.elementLocated(By.id("submitLoginButton")),
              defaultTimeout
            )

            .then((e) => (e.click(), Promise.resolve(!0)))
        );
      })

      .then(
        function () {
          logger.endTestCase("Consulta de estoque Argetina");
        },
        function (err) {
          logger.error(err, "Consulta de estoque Argetina");
          throw err;
        }
      );
  });

image