0

I am in a project in which I am making a modular behavior driven framework for the company I am working right now. In making a modular approach of the step "user accepts alert", when I test it and came an expected alert box, it automatically closes itself and therefore shows this "NoAlertPresentException: Message: No alert is present" exception.

I have done this codes so far:

def acceptalert():
    alert = driver.switch_to.alert
    alert.accept()
    driver.switch_to.parent_frame()

This code snippet works as I have those modules in which I incorporated the closing of alert box. The only problem is just when I try to make this one a standalone module in my framework. I have done research with this one but I really never got my problem answered. I hope there will be one in here who can help me. Thank you very much.

  • So what is wrong with your code? It's not quite clear what is the problem... Does alert sometimes closes before you accept it and so you get `NoAlertPresentException`? – Andersson Dec 05 '16 at 12:30

1 Answers1

0

Found the answer. Thank you. I implemented the step "user clicks '' button" where is the value of the button being matched with a series of xpath and if the xpath returns zero match, then it fetches the available iframes and loops inside each one. When the xpath still returned zero matches, then it switches back to the main frame with this peace of code:

driver.switch_to.parent_frame()

The side effect with this one is it will dismiss the alert boxes. My problem is solved. Thanks everyone.