Python selenium.common.exceptions.NoAlertPresentException() Examples
The following are 21
code examples of selenium.common.exceptions.NoAlertPresentException().
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: formgrade_utils.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #2
Source File: webelement.py From knitter with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: webelement.py From knitter with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: test_selenium.py From ckanext-privatedatasets with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #5
Source File: conftest.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _close_browser(browser): browser.save_screenshot(os.path.join(os.path.dirname(__file__), 'selenium.screenshot.png')) browser.get("about:blank") try: alert = browser.switch_to.alert except NoAlertPresentException: pass else: print("Warning: dismissing unexpected alert ({})".format(alert.text)) alert.accept() browser.quit()
Example #6
Source File: test_validate_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _load_notebook(browser, port, notebook, retries=5): # go to the correct page url = "http://localhost:{}/notebooks/{}.ipynb".format(port, notebook) browser.get(url) alert = '' for _ in range(5): if alert is None: break try: alert = browser.switch_to.alert except NoAlertPresentException: alert = None else: print("Warning: dismissing unexpected alert ({})".format(alert.text)) alert.accept() def page_loaded(browser): return browser.execute_script( """ return (typeof Jupyter !== "undefined" && Jupyter.page !== undefined && Jupyter.notebook !== undefined && $("#notebook_name").text() === "{}"); """.format(notebook)) # wait for the page to load try: _wait(browser).until(page_loaded) except TimeoutException: if retries > 0: print("Retrying page load...") # page timeout, but sometimes this happens, so try refreshing? _load_notebook(browser, port, retries=retries - 1, notebook=notebook) else: print("Failed to load the page too many times") raise
Example #7
Source File: alert.py From nerodia with MIT License | 5 votes |
def assert_exists(self): try: self.alert = self.browser.driver.switch_to.alert except NoAlertPresentException: raise UnknownObjectException('unable to locate alert')
Example #8
Source File: extended_driver.py From golem with MIT License | 5 votes |
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
Example #9
Source File: extended_driver.py From golem with MIT License | 5 votes |
def alert_is_present(self): """Returns whether an alert is present""" try: self.switch_to.alert return True except NoAlertPresentException: return False
Example #10
Source File: extended_driver.py From golem with MIT License | 5 votes |
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
Example #11
Source File: windows_handler.py From webium with Apache License 2.0 | 5 votes |
def is_alert_present(self): try: self.get_alert_text() return True except NoAlertPresentException: return False
Example #12
Source File: selenium_ide_intro.py From youtube_tutorials with GNU General Public License v3.0 | 5 votes |
def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True
Example #13
Source File: test.py From epater with GNU General Public License v3.0 | 5 votes |
def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True
Example #14
Source File: crawler.py From coverage-crawler with Mozilla Public License 2.0 | 5 votes |
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])
Example #15
Source File: WebTester.py From PyWebRunner with MIT License | 5 votes |
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
Example #16
Source File: WebTester.py From PyWebRunner with MIT License | 5 votes |
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
Example #17
Source File: collect.py From autowebcompat with Mozilla Public License 2.0 | 5 votes |
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])
Example #18
Source File: SeleniumTest.py From INGInious with GNU Affero General Public License v3.0 | 5 votes |
def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True
Example #19
Source File: webdriver.py From poium with Apache License 2.0 | 5 votes |
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
Example #20
Source File: foctor_core.py From centinel with MIT License | 4 votes |
def load_page(driver, url, cookies=0): try: if cookies == 0: driver.delete_all_cookies() time.sleep(1) if "http" not in url.split("/")[0]: url = "http://" + url switch_tab(driver) driver.get(url) logging.debug("driver.get(%s) returned successfully" % url) except (TimeoutException, TimeoutError) as te: logging.warning("Loading %s timed out" % url) return str(te) # try: # element = WebDriverWait(driver, .5).until(EC.alert_is_present()) # if element is not None: # print "Alert found on page: " + url # sys.stdout.flush() # raise TimeoutError # else: # raise NoAlertPresentException # except (TimeoutException, NoAlertPresentException): # print "No alert found on page: " + url # sys.stdout.flush() # pass # except TimeoutError as te: # sys.stdout.flush() # return str(te) # try: # main_handle = driver.current_window_handle # except CannotSendRequest as csr: # return str(csr) try: windows = driver.window_handles if len(windows) > 1: logging.debug("Pop up detected on page: %s. Closing driver instance." % url) raise TimeoutError # for window in windows: # if window != main_handle: # driver.switch_to_window(window) # driver.close() # driver.switch_to_window(main_handle) # wfrs_status = wait_for_ready_state(driver, 15, 'complete') # if wfrs_status == "Timed-out": # print "wait_for_ready_state() timed out." # raise TimeoutError except (TimeoutException, TimeoutError) as te: logging.warning("Loading %s timed out" % url) return str(te) return "No Error"
Example #21
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _load_notebook(browser, port, retries=5, name="blank"): # go to the correct page url = "http://localhost:{}/notebooks/{}.ipynb".format(port, name) browser.get(url) alert = '' for _ in range(5): if alert is None: break try: alert = browser.switch_to.alert except NoAlertPresentException: alert = None else: print("Warning: dismissing unexpected alert ({})".format(alert.text)) alert.accept() def page_loaded(browser): return browser.execute_script( """ return (typeof Jupyter !== "undefined" && Jupyter.page !== undefined && Jupyter.notebook !== undefined && $("#notebook_name").text() === "{}" && Jupyter.notebook._fully_loaded); """.format(name)) # wait for the page to load try: _wait(browser).until(page_loaded) except TimeoutException: if retries > 0: print("Retrying page load...") # page timeout, but sometimes this happens, so try refreshing? _load_notebook(browser, port, retries=retries - 1, name=name) else: print("Failed to load the page too many times") raise # Hack: there seems to be some race condition here where sometimes the # page is still not fully loaded, but I can't figure out exactly what I need # to check for to ensure that it is. So for now just add a small sleep to # make sure everything finishes loading, though this is not really a robust # fix for the problem :/ time.sleep(1) # delete all cells if name == "blank": cells = browser.find_elements_by_css_selector(".cell") for _ in range(len(cells)): element = browser.find_elements_by_css_selector(".cell")[0] element.click() element.send_keys(Keys.ESCAPE) element.send_keys("d") element.send_keys("d")