0

i mean on:

alert("Hello! I am an alert box!!");

can i accept it with code?

cuz i cant actually even write code on the console when an alerts pops, so I even tried stuff like:

function sleep(ms) 
{
  return new Promise(resolve => setTimeout(resolve, ms));
}

// this line above is to wait for X time until the code executes
async function whatEver()
{
  await sleep(5000);
  alert.accept();
}

async function whatEver2()
{
  await sleep(5000);
  new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent()).accept();
}
}

And none will work, is it even possible to accept the alerts with code? if so, appreciate any help orienting me :)

  • Wait, what is that code? You're using WebDriver, so are you automating interactions on a page via Selenium or something? – VLAZ May 14 '21 at 14:55
  • 1
    Does this answer your question? [Javascript close alert box](https://stackoverflow.com/questions/463368/javascript-close-alert-box) – Showrin Barua May 14 '21 at 14:58
  • 3
    The real answer is: no-one uses `alert()` for anything other than a quick debug (and then console.log is better). If you're using `alert()` in production code (to be used by "*users*"...) then give your developers a slap from me and fail the test. – freedomn-m May 14 '21 at 15:11

0 Answers0