How do you handle Alert in Selenium?

How do you handle Alert in Selenium?

In Selenium, the following methods are useful for handling alerts: When the ‘Cancel’ button in the alert box is hit, the void dismiss() method is called. Accept() is a void method that is used to click the alert’s ‘OK’ button… This method is used to grab the alert message. String getText(): This method is used to capture the alert message.