Python selenium.common.exceptions.UnexpectedAlertPresentException() Examples

The following are 9 code examples of selenium.common.exceptions.UnexpectedAlertPresentException(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.common.exceptions , or try the search function .
Example #1
Source File: exe.py    From ScreenShooter with MIT License 6 votes vote down vote up
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 
Example #2
Source File: webelement.py    From knitter with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #3
Source File: webelement.py    From knitter with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #4
Source File: test_alert.py    From selenium-python-helium with MIT License 5 votes vote down vote up
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
		) 
Example #5
Source File: test_alert.py    From selenium-python-helium with MIT License 5 votes vote down vote up
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
		) 
Example #6
Source File: test_alert.py    From selenium-python-helium with MIT License 5 votes vote down vote up
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 
Example #7
Source File: test_alert.py    From selenium-python-helium with MIT License 5 votes vote down vote up
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
		) 
Example #8
Source File: test_alert.py    From selenium-python-helium with MIT License 5 votes vote down vote up
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
		) 
Example #9
Source File: webelement.py    From knitter with GNU General Public License v3.0 5 votes vote down vote up
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))