当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.NoSuchWindowException方法代码示例

本文整理汇总了Python中selenium.common.exceptions.NoSuchWindowException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NoSuchWindowException方法的具体用法?Python exceptions.NoSuchWindowException怎么用?Python exceptions.NoSuchWindowException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.common.exceptions的用法示例。


在下文中一共展示了exceptions.NoSuchWindowException方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_window_handle

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def find_window_handle(webdriver, predicate):
    original_window_handle = webdriver.current_window_handle
    if predicate(webdriver):
        return original_window_handle

    # Start search beginning with the most recently added window handle: the chance is higher that this is the correct
    # one in most cases
    for window_handle in reversed(webdriver.window_handles):
        if window_handle == original_window_handle:
            continue

        # This exception can occur if the window handle was closed between accessing the window handles and attempting
        # to switch to it, in which case it can be silently ignored.
        try:
            webdriver.switch_to.window(window_handle)
        except NoSuchWindowException:
            continue

        if predicate(webdriver):
            return window_handle

    # Simply switch back to the original window handle and return None if no matching window handle was found
    webdriver.switch_to.window(original_window_handle) 
开发者ID:cryzed,项目名称:Selenium-Requests,代码行数:25,代码来源:request.py

示例2: openChrome

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def openChrome(paydetailsO, itemdetsO, timeO, strictO, skipO, nextO, cdloc, capabilities, useProxy, PROXY):
    global driver, strict, password, reg, items, droptime, pDescr, paydetails, category, skipS, nextS
    chrome_options = webdriver.ChromeOptions()
    if useProxy:
        prx = Proxy()
        prx.proxy_type = ProxyType.MANUAL
        prx.http_proxy = PROXY
        prx.socks_proxy = PROXY
        prx.ssl_proxy = PROXY
        prx.add_to_capabilities(capabilities)
    else:
        prx = Proxy()
        prx.proxy_type = ProxyType.SYSTEM
        prx.add_to_capabilities(capabilities)

    chrome_options.binary_location = capabilities['chrome.binary']

    driver = webdriver.Chrome(cdloc, desired_capabilities=capabilities)
    openTab('https://www.google.com', driver)
    paydetails = paydetailsO
    reg = paydetailsO['Region']
    strict = strictO
    skipS = skipO
    nextS = nextO
    droptime = timeO
    items = []
    for x in itemdetsO:
        print(x[0],x[1],x[2],x[3])
        items.append({'selectedCategory': x[0], 'keywords': x[1].split(','), 'selectedColour': x[2], 'selectedSize': x[3]})
    returnTime()
    try:
        for it in items:
                searchItem(it)
        cart()
    except NoSuchWindowException:
        print('[!] Chrome window closed. Click GO! to re-start')
        return None 
开发者ID:danielyc,项目名称:csb,代码行数:39,代码来源:bot.py

示例3: close_all_windows_except_first

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [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]) 
开发者ID:marco-c,项目名称:autowebcompat,代码行数:17,代码来源:collect.py

示例4: switch_window

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def switch_window(self, handle=None):
        """
        Switches window.

        If there are only 2 windows, it can work out which window to switch to.
        Otherwise, you should pass in the window handle as `handle` kwarg.

        Returns a tuple (old_window_handle, new_window_handle)
        """
        try:
            current_window_handle = self._driver.current_window_handle
        except NoSuchWindowException:
            # Window closed recently
            current_window_handle = None
        window_handles = self._driver.window_handles
        if handle is None:
            possible_window_handles = [h for h in window_handles
                                       if h != current_window_handle]

            if len(possible_window_handles) > 1:
                raise AssertionError("Don't know which window to switch to!")
            else:
                handle = possible_window_handles[0]

        def f(driver):
            if (hasattr(driver, 'switch_to') and
                    hasattr(driver.switch_to, 'window')):
                m = driver.switch_to.window
            else:
                m = driver.switch_to_window
            m(handle)
            return driver.current_window_handle == handle
        self.wait_until(f)
        return current_window_handle, handle 
开发者ID:django-functest,项目名称:django-functest,代码行数:36,代码来源:funcselenium.py

示例5: _wait_until_finished

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def _wait_until_finished(self):
        try:
            self.wait_for_page_load()
        except NoSuchWindowException:
            pass  # window can legitimately close e.g. for popups 
开发者ID:django-functest,项目名称:django-functest,代码行数:7,代码来源:funcselenium.py

示例6: current_tab_id

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def current_tab_id(self):
        try:
            return self.driver.current_window_handle
        except selenium_exceptions.NoSuchWindowException:
            print('Failed to get current tab_id, likely close. Switch to tab 0')
            try:
                self.to_tab_by_index(0)
                return self.driver.current_window_handle
            except:
                print('Still failed to get current tab_id')
                raise
        except:
            print('Failed to get current tab_id for unexpected reason')
            raise 
开发者ID:qks1lver,项目名称:redtide,代码行数:16,代码来源:api.py

示例7: make_match_domain_predicate

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def make_match_domain_predicate(domain):
    def predicate(webdriver):
        try:
            return get_tld(webdriver.current_url) == domain
        # This exception can occur if the current window handle was closed
        except NoSuchWindowException:
            pass

    return predicate 
开发者ID:cryzed,项目名称:Selenium-Requests,代码行数:11,代码来源:request.py

示例8: _matches

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def _matches(self, handle):
        try:
            orig = self.driver.current_window_handle
        except NoSuchWindowException:
            orig = None
        try:
            self.driver.switch_to.window(handle)

            if 'title' in self.selector:
                title_value = self.selector.get('title')
                driver_title = self.browser.title
                matches_title = re.search(title_value, driver_title) is not None
            else:
                matches_title = True

            if 'url' in self.selector:
                url_value = self.selector.get('url')
                driver_url = self.browser.url
                matches_url = re.search(url_value, driver_url) is not None
            else:
                matches_url = True

            return matches_title and matches_url
        except (NoSuchWindowException, WebDriverException):
            return False
        finally:
            current = self.driver.window_handles
            orig = orig if orig in current else current[0]
            self.driver.switch_to.window(orig) 
开发者ID:watir,项目名称:nerodia,代码行数:31,代码来源:window.py

示例9: run

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def run(self):
        """ Runs after hooks """
        # We can't just rescue exception because Firefox automatically closes alert when
        # exception raised
        try:
            if self.after_hooks and not self.browser.alert.exists:
                for hook in self.after_hooks:
                    hook(self.browser)
        except NoSuchWindowException as e:
            nerodia.logger.info('Could not execute After Hooks because browser window was '
                                'closed {}'.format(e)) 
开发者ID:watir,项目名称:nerodia,代码行数:13,代码来源:after_hooks.py

示例10: click

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchWindowException [as 别名]
def click(self, css_selector=None, xpath=None,
              text=None, text_parent_id=None,
              wait_for_reload=False,
              wait_timeout=None,
              double=False, scroll=True, window_closes=False):
        """
        Clicks the button or control specified by the CSS selector
        or xpath
        """
        if window_closes:
            wait_for_reload = False
        if wait_for_reload:
            self._driver.execute_script("document.pageReloadedYetFlag='notyet';")

        elem = self._find_with_timeout(css_selector=css_selector,
                                       xpath=xpath,
                                       text=text,
                                       text_parent_id=text_parent_id,
                                       timeout=wait_timeout)
        if scroll:
            self._scroll_into_view(elem)
        elem.click()
        if double:
            try:
                elem.click()
            except StaleElementReferenceException:
                pass

        if wait_for_reload:
            def f(driver):
                obj = driver.execute_script("return document.pageReloadedYetFlag;")

                if obj is None or obj != "notyet":
                    return True
                return False
            try:
                WebDriverWait(self._driver, self.get_default_timeout()).until(f)
            except NoSuchWindowException:
                # legitimate sometimes e.g. when window closes
                pass
        if not window_closes:
            self._wait_until_finished() 
开发者ID:django-functest,项目名称:django-functest,代码行数:44,代码来源:funcselenium.py


注:本文中的selenium.common.exceptions.NoSuchWindowException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。