0

Usually, alerts in selenium are handled by switching to alert using driver.swichto().alert(); Alert can be of prompt , confirm or simple type.

I need help in finding the type of alert occurred to trigger the appropriate operation

Thanks In advance..!!

rama krishna
  • 35
  • 1
  • 8
  • `driver.swichto().alert();` can be used to handle `alert()`, `confirm()` and `prompt()`... What kind of "appropriate operation" you mean? – Andersson Mar 26 '17 at 11:57
  • Possible duplicate of [Alert handling in Selenium WebDriver (selenium 2) with Java](http://stackoverflow.com/questions/8244723/alert-handling-in-selenium-webdriver-selenium-2-with-java) – JeffC Mar 26 '17 at 18:20
  • The type of alert doesn't matter, they are all classified as alerts so the Selenium code doesn't change. – JeffC Mar 26 '17 at 18:20

1 Answers1

0

There are certain types of Alerts.

  1. First one is the normal Alert where we use accept() & dismiss() to handle it. Elements of this type of Alerts are not part of the HTML DOM. For this type of Alerts you need handle as below:

    //Switch to the Alert & Dismiss

    driver.switchTo().alert().dismiss();

or

   //Switch to Alert & Accept
    driver.switchTo().alert().accept();
  1. Next is the Boot strapped Modal Dialoge which looks like an Alert but actually its not an Alert. In this case in addition to the buttons for "OK" & "Close" you may have an additional text field to send some text. e.g. your email id. Elements of this type of Alerts are part of the HTML DOM. Hence the attributes of the elements of the Boot Strapped Modal Dialogue box can be easily detected to perform the required operation on them.

Let me know if this answers your question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352