本文整理汇总了Python中selenium.common.exceptions.NoAlertPresentException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NoAlertPresentException方法的具体用法?Python exceptions.NoAlertPresentException怎么用?Python exceptions.NoAlertPresentException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.common.exceptions
的用法示例。
在下文中一共展示了exceptions.NoAlertPresentException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlertAccept
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def AlertAccept(self):
logger.step_normal("AlertAccept()")
time.sleep(2)
try:
logger.step_normal("switch_to_alert()")
alert = Browser.RunningBrowser.switch_to_alert()
alert.accept()
except NoAlertPresentException:
logger.step_normal("Alert Not Found. ")
try:
logger.step_normal("switch_to_default_content()")
Browser.RunningBrowser.switch_to_default_content()
except Exception as e:
logger.step_warning(e)
pass
示例2: AlertDismiss
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def AlertDismiss(self):
logger.step_normal("AlertDismiss()")
time.sleep(2)
try:
logger.step_normal("switch_to_alert()")
alert = Browser.RunningBrowser.switch_to_alert()
alert.dismiss()
except NoAlertPresentException:
logger.step_normal("Alert Not Found.")
try:
logger.step_normal("switch_to_default_content()")
Browser.RunningBrowser.switch_to_default_content()
except Exception as e:
logger.step_normal(e)
pass
示例3: _get
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def _get(browser, url, retries=5):
try:
browser.get(url)
assert browser.get_cookies()
except TimeoutException:
if retries == 0:
raise
else:
print("Failed to load '{}', trying again...".format(url))
_get(browser, url, retries=retries - 1)
try:
alert = browser.switch_to.alert
except NoAlertPresentException:
pass
else:
print("Warning: dismissing unexpected alert ({})".format(alert.text))
alert.accept()
示例4: is_alert_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True
示例5: alert_is_display
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def alert_is_display(self):
"""
selenium API
Determines if alert is displayed
"""
try:
self.driver.switch_to.alert
except NoAlertPresentException:
return False
else:
return True
示例6: close_all_windows_except_first
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def close_all_windows_except_first(driver):
windows = driver.window_handles
for window in windows[1:]:
driver.switch_to_window(window)
driver.close()
while True:
try:
alert = driver.switch_to_alert()
alert.dismiss()
except (NoAlertPresentException, NoSuchWindowException):
break
driver.switch_to_window(windows[0])
示例7: assert_alert_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
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
示例8: assert_alert_not_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
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
示例9: is_alert_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
示例10: tearDown
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def tearDown(self):
self.driver.get(self.base_url)
try: # pragma: no cover
# Accept any "Are you sure to leave?" alert
self.driver.switch_to.alert.accept()
self.driver.switch_to.default_content()
except NoAlertPresentException:
pass
WebDriverWait(self.driver, 10).until(lambda driver: self.base_url == driver.current_url)
self.driver.delete_all_cookies()
self.clearBBDD()
示例11: is_alert_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def is_alert_present(self):
try:
self.get_alert_text()
return True
except NoAlertPresentException:
return False
示例12: accept_alert
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def accept_alert(self, ignore_not_present=False):
"""Accepts alert.
:Args:
- ignore_not_present: ignore NoAlertPresentException
"""
try:
self.switch_to.alert.accept()
except NoAlertPresentException:
if not ignore_not_present:
raise
示例13: alert_is_present
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def alert_is_present(self):
"""Returns whether an alert is present"""
try:
self.switch_to.alert
return True
except NoAlertPresentException:
return False
示例14: dismiss_alert
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def dismiss_alert(self, ignore_not_present=False):
"""Dismiss alert.
:Args:
- ignore_not_present: ignore NoAlertPresentException
"""
try:
self.switch_to.alert.dismiss()
except NoAlertPresentException:
if not ignore_not_present:
raise
示例15: assert_exists
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoAlertPresentException [as 别名]
def assert_exists(self):
try:
self.alert = self.browser.driver.switch_to.alert
except NoAlertPresentException:
raise UnknownObjectException('unable to locate alert')