Common automated test scripts - treatment of alert boxes and pop-up box

'''确认警报框'''
def remove_alarm_box(self, typ=None):
    """
    :param typ: 处理类型
    :return: 警报框文本
    """
    if self.is_present_alert():
        alert = self.dr.switch_to.alert
        tx = alert.text
        if typ is None or typ.strip() == "确定":
            alert.accept()
        elif typ.strip() == "取消":
            alert.dismiss()
        else:
            print("您输入的提示框操作有误。请输入'确定'或'取消'")
        sleep(2)
        return tx
'''判断弹出框是否出现'''
def is_present_alert(self):
    try:
        WebDriverWait(self.dr, 5, 1).until(EC.alert_is_present())
        return True
    except Exception:
        return False

Guess you like

Origin www.cnblogs.com/chenri/p/11605545.html