import yaml
def handle_black(fun):
    def run(*args, **kwargs):
        instance = args[0]
        with open("../blacklist.yaml","r",encoding="utf-8") as f:
            black_lists = yaml.safe_load(f)
            # 捕获异常（元素没找到）
        try:
            # 如果元素找到，就返回
            return fun(*args, **kwargs)
        except Exception as e:
            # 遍历黑名单的元素
            for black in black_lists:
                eles = instance.driver.find_elements(*black)
                # 如果存在黑名单元素
                if len(eles)>0:
                    # 点击关闭弹窗
                    eles[0].click()
                    #再次查找
                    return fun(*args, **kwargs)
                raise e
    return run

