简体   繁体   中英

How to get the get of alert shown using selenium

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..!!

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. eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM