How can I detect when a javascript alert box is OK'ed and/or closed?
Selenium has multiple APIs to handle alerts with an Alert interface. To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method.
One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.
The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.
prompt. shows a message asking the user to input text. It returns the text or, if Cancel button or Esc is clicked, null . confirm. shows a message and waits for the user to press “OK” or “Cancel”.
Since alert
is blocking:
alert('foo'); function_to_call_when_oked_or_closed();
Just put the function after the call to alert
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With