WebDriver offers an efficient way to handle web-based pop-ups using the Alert interface. Developers can use the below mentioned four methods, along with the Alert interface, for treating web-based pop-ups:

  • void dismiss(): Accept() way clicks “Cancel” when window pop-ups appear.
  • void accept(): Accept() method clicks “Ok” button when window pop-ups appear.
  • String getText(): GetText() method returns the text shown on alert box.
  • void sendKeys(String stringToSend): SendKeys() method enters specified string pattern into alert box.
BY Best Interview Question ON 26 Jan 2019