Python selenium.common.exceptions 模块,NoAlertPresentException() 实例源码

我们从Python开源项目中,提取了以下28个代码示例,用于说明如何使用selenium.common.exceptions.NoAlertPresentException()

项目:YOHO_Automated_Test    作者:yzwy1988    | 项目源码 | 文件源码
def AlertAccept(cls):
        log.step_normal("AlertAccept()")

        i = 0
        while i < 60:
            try:
                log.step_normal("switch_to_alert()")
                alert = env.driver.switch_to_alert()
                alert.accept()
                break
            except NoAlertPresentException:
                log.step_normal("Alert Not Found. Wait 3 Seconds then Try Again!")
                time.sleep(3)

        try:
            log.step_normal("switch_to_default_content()")
            env.driver.switch_to_default_content()
        except:
            pass
项目:YOHO_Automated_Test    作者:yzwy1988    | 项目源码 | 文件源码
def AlertDismiss(cls):
        log.step_normal("AlertDismiss()")

        i = 0
        while i < 60:
            try:
                log.step_normal("switch_to_alert()")
                alert = env.driver.switch_to_alert()
                alert.dismiss()
                break
            except NoAlertPresentException:
                log.step_normal("Alert Not Found. Wait 3 Seconds then Try Again!")
                time.sleep(3)

        try:
            log.step_normal("switch_to_default_content()")
            env.driver.switch_to_default_content()
        except:
            pass
项目:brush    作者:chenshiyang2015    | 项目源码 | 文件源码
def AlertAccept(cls):#??Alert??? ??
        log.step_normal("AlertAccept()")

        time.sleep(2)
        try:
            log.step_normal("switch_to_alert()")
            alert = env.threadlocal.BROWSER.switch_to_alert()
            alert.accept()
        except NoAlertPresentException:
            log.step_normal("Alert Not Found. ")

        try:
            log.step_normal("switch_to_default_content()")
            env.threadlocal.BROWSER.switch_to_default_content()
        except:
            pass
项目:brush    作者:chenshiyang2015    | 项目源码 | 文件源码
def AlertDismiss(cls): #??Alert??? ??
        log.step_normal("AlertDismiss()")

        time.sleep(2)
        try:
            log.step_normal("switch_to_alert()")
            alert = env.threadlocal.BROWSER.switch_to_alert()
            alert.dismiss()
        except NoAlertPresentException:
            log.step_normal("Alert Not Found.")

        try:
            log.step_normal("switch_to_default_content()")
            env.threadlocal.BROWSER.switch_to_default_content()
        except:
            pass
项目:PyWebRunner    作者:IntuitiveWebSolutions    | 项目源码 | 文件源码
def assert_alert_present(self):
        '''
        Asserts that an alert exists.

        '''
        alert = self.browser.switch_to_alert()
        msg = 'An alert was not present but was expected.'

        try:
            atext = bool(alert.text)
        except NoAlertPresentException:
            atext = False

        assert atext == True, msg
项目:PyWebRunner    作者:IntuitiveWebSolutions    | 项目源码 | 文件源码
def assert_alert_not_present(self):
        '''
        Asserts that an alert does not exist.

        '''
        def check_text(alert):
            bool(alert.text)

        alert = self.browser.switch_to_alert()
        present = False
        try:
            present = bool(alert.text)
        except NoAlertPresentException:
            pass
        assert present == False
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:playground    作者:CastalioPodcast    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:webbreaker    作者:target    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:webbreaker    作者:target    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:nerodia    作者:watir    | 项目源码 | 文件源码
def assert_exists(self):
        try:
            self.alert = self.browser.driver.switch_to.alert
            self.alert.text
        except NoAlertPresentException:
            raise UnknownObjectException('unable to locate alert')
项目:crawler_sqlmap    作者:CvvT    | 项目源码 | 文件源码
def click_buttons(self):
        """

        consider the consequence of clicking buttons:
        1. redirect: well, redirecting usually occurs with tag 'a' rather than 'button' or 'input', so I
                    ignore this situation right now. Maybe I shouldn't?
        2. alert: handler alert well
        :return:
        """
        btns = self.find_elements_by_tag_name("button")
        for btn in btns:
            try:
                logger.debug("find a button and click on it")
                btn.click()
                self.switch_to.alert.accept()
            except NoAlertPresentException:
                pass
            except:
                traceback.print_exc()
        btns = self.find_elements_by_xpath('//input[@type="button"]')
        # btns = self.find_elements_by_xpath('//input[@onclick]')
        for btn in btns:
            try:
                btn.click()
                self.switch_to.alert.accept()
            except NoAlertPresentException:
                pass
            except:
                traceback.print_exc()
            # it seems like we can declare that the button isn't inside a form
            # make sure it isn't inside a form
            # try:
            #     form = btn.find_element_by_xpath('./ancestor::form')
            # except NoSuchElementException:
            #     try:
            #         btn.click()
            #     except:
            #         traceback.print_exc()
            # else:
            #     logger.debug("it is inside a form")
项目:ShuoshuoMonitor    作者:aploium    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:synergy_website    作者:alfredojf    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:amazon_order_history_scraper    作者:drewctate    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:webtech16-public    作者:tthelen    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def __call__(self, driver):
        try:
            alert = driver.switch_to.alert
            alert.text
            return alert
        except NoAlertPresentException:
            return False
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def is_alert_present(self):
        try:
            self.driver.switch_to_alert()
        except NoAlertPresentException:
            return False
        return True
项目:epater    作者:mgard    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
项目:Zeuz_Python_Node    作者:AutomationSolutionz    | 项目源码 | 文件源码
def Handle_Browser_Alert(step_data):
    #accepts browser alert
    sModuleInfo = inspect.stack()[0][3] + " : " + inspect.getmoduleinfo(__file__).name
    try:
        choice = str(step_data[0][2]).lower()
        if choice == 'accept' or choice == 'pass' or choice == 'yes' or choice == 'ok':
            try:
                selenium_driver.switch_to_alert().accept()
                CommonUtil.ExecLog(sModuleInfo, "Browser alert accepted", 1)
                return "passed"
            except NoAlertPresentException as e:
                CommonUtil.ExecLog(sModuleInfo, "Browser alert not found", 2)
                return "passed"
        elif choice == 'reject' or choice == 'fail' or choice == 'no' or choice == 'cancel':
            try:
                selenium_driver.switch_to_alert().dismiss()
                CommonUtil.ExecLog(sModuleInfo, "Browser alert rejected", 1)
                return "passed"
            except NoAlertPresentException as e:
                CommonUtil.ExecLog(sModuleInfo, "Browser alert not found", 2)
                return "passed"
        else:
            CommonUtil.ExecLog(sModuleInfo, "Wrong Step Data", 3)
            return "failed"

    except Exception:
        ErrorMessage =  "Failed to accept browser alert"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, ErrorMessage)
项目:youtube_tutorials    作者:vprusso    | 项目源码 | 文件源码
def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True