本文整理匯總了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')