本文整理汇总了Python中selenium.common.exceptions.UnexpectedAlertPresentException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.UnexpectedAlertPresentException方法的具体用法?Python exceptions.UnexpectedAlertPresentException怎么用?Python exceptions.UnexpectedAlertPresentException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.common.exceptions
的用法示例。
在下文中一共展示了exceptions.UnexpectedAlertPresentException方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeScreen
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def makeScreen(name, url, driver):
try:
driver.get(url)
screenshot = driver.save_screenshot(basename + '/' + str(name) + '.png')
appendHTML(name, url)
print('[-] Screenshooted: ' + url)
return True
except UnexpectedAlertPresentException as e:
print('[!] Error: ' + str(e))
err.append(url)
return False
except TimeoutException as t:
print('[!] Timeout: ' + str(t))
err.append(url)
return False
示例2: __wait_for_appearing
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def __wait_for_appearing(self):
t = 0
while t < 120:
t = t + 1
try:
elements = Browser.RunningBrowser.find_elements(self.by, self.value)
except NoSuchElementException:
logger.step_normal("Element [%s]: NoSuchElementException." % self.__name__)
elements = []
continue
except UnexpectedAlertPresentException:
logger.step_warning("Element [%s]: UnexpectedAlertPresentException." % self.__name__)
if len(elements) == 0:
time.sleep(0.5)
logger.step_normal("Element [%s]: WaitForAppearing... Wait 1 second, By [%s]" % (self.__name__,
self.value))
else:
logger.step_normal("Element [%s]: Found [%s] Element. Tried [%s] Times." % (self.__name__,
len(elements), t))
break
示例3: __wait_for_disappearing
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def __wait_for_disappearing(self):
t = 0
while t < 120:
t = t + 1
try:
elements = Browser.RunningBrowser.find_elements(self.by, self.value)
except NoSuchElementException:
logger.step_normal("Element [%s]: NoSuchElementException." % self.__name__)
elements = []
continue
except UnexpectedAlertPresentException:
logger.step_warning("Element [%s]: UnexpectedAlertPresentException." % self.__name__)
if len(elements) == 0:
return True
else:
time.sleep(0.5)
logger.step_normal("Element [%s]: WairForDisappearing... Found [%s] Element. Tried [%s] Times." %
(self.__name__, len(elements), t))
return False
示例4: test_click_with_open_alert_raises_exception
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def test_click_with_open_alert_raises_exception(self):
with self.assertRaises(UnexpectedAlertPresentException) as cm:
click("OK")
msg = self._get_unhandled_alert_exception_msg(cm.exception)
self.assertEqual(
self.UNEXPECTED_ALERT_PRESENT_EXCEPTION_MSG, msg
)
示例5: test_press_with_open_alert_raises_exception
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def test_press_with_open_alert_raises_exception(self):
with self.assertRaises(UnexpectedAlertPresentException) as cm:
press(ENTER)
msg = self._get_unhandled_alert_exception_msg(cm.exception)
self.assertEqual(
self.UNEXPECTED_ALERT_PRESENT_EXCEPTION_MSG, msg
)
示例6: _get_unhandled_alert_exception_msg
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def _get_unhandled_alert_exception_msg(self, e):
if selenium.__version__ == '2.43.0':
# Selenium 2.43.0 has a regression where accessing the .msg field
# of an UnexpectedAlertPresentException raises an AttributeError -
# See: https://code.google.com/p/selenium/issues/detail?id=7886
return e.args[0]
else:
return e.msg
示例7: test_write_into_label_raises_exception
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def test_write_into_label_raises_exception(self):
with self.assertRaises(UnexpectedAlertPresentException) as cm:
write("3", into="Please enter a value")
msg = self._get_unhandled_alert_exception_msg(cm.exception)
self.assertEqual(
self.UNEXPECTED_ALERT_PRESENT_EXCEPTION_MSG, msg
)
示例8: test_write_into_text_field_raises_exception
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def test_write_into_text_field_raises_exception(self):
with self.assertRaises(UnexpectedAlertPresentException) as cm:
write("4", into=TextField("Please enter a value"))
msg = self._get_unhandled_alert_exception_msg(cm.exception)
self.assertEqual(
self.UNEXPECTED_ALERT_PRESENT_EXCEPTION_MSG, msg
)
示例9: __wait
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import UnexpectedAlertPresentException [as 别名]
def __wait(self):
t = 0
while t < 300:
t = t + 1
try:
elements = Browser.RunningBrowser.find_elements(self.by, self.value)
except NoSuchElementException:
logger.step_normal("Element [%s]: NoSuchElementException." % self.__name__)
elements = []
except UnexpectedAlertPresentException:
logger.step_warning("Element [%s]: UnexpectedAlertPresentException." % self.__name__)
if len(elements) == 0:
time.sleep(1)
logger.step_normal("Element [%s]: Wait 1 second, By [%s :: %s :: %s]" % (self.__name__,
self.by,
self.value,
self.index))
else:
if len(elements) > 1:
logger.step_normal("Element [%s]: There are [%s] Elements!" % (self.__name__, len(elements)))
break
if len(elements) < self.index + 1:
logger.step_fail("Element [%s]: Element Index Issue! There are [%s] Elements! Index=[%s]" % (self.__name__,
len(elements),
self.index))