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


Python exceptions.NoSuchElementException方法代码示例

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


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

示例1: _expected_condition_find_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def _expected_condition_find_element(self, element):
        """Tries to find the element, but does not thrown an exception if the element is not found

        :param element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
        :returns: the web element if it has been found or False
        :rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
        """
        from toolium.pageelements.page_element import PageElement
        web_element = False
        try:
            if isinstance(element, PageElement):
                # Use _find_web_element() instead of web_element to avoid logging error message
                element._web_element = None
                element._find_web_element()
                web_element = element._web_element
            elif isinstance(element, tuple):
                web_element = self.driver_wrapper.driver.find_element(*element)
        except NoSuchElementException:
            pass
        return web_element 
开发者ID:Telefonica,项目名称:toolium,代码行数:22,代码来源:driver_utils.py

示例2: _expected_condition_find_first_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def _expected_condition_find_first_element(self, elements):
        """Try to find sequentially the elements of the list and return the first element found

        :param elements: list of PageElements or element locators as a tuple (locator_type, locator_value) to be found
                         sequentially
        :returns: first element found or None
        :rtype: toolium.pageelements.PageElement or tuple
        """
        from toolium.pageelements.page_element import PageElement
        element_found = None
        for element in elements:
            try:
                if isinstance(element, PageElement):
                    element._web_element = None
                    element._find_web_element()
                else:
                    self.driver_wrapper.driver.find_element(*element)
                element_found = element
                break
            except (NoSuchElementException, TypeError):
                pass
        return element_found 
开发者ID:Telefonica,项目名称:toolium,代码行数:24,代码来源:driver_utils.py

示例3: save_ads_linkedin

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def save_ads_linkedin(self, file_name=None):
    id = self.unit_id
    sys.stdout.write(".")
    sys.stdout.flush()
    self.driver.set_page_load_timeout(60)

    self.search_term()
    time = str(datetime.now())
    lis = self.driver.find_elements_by_css_selector('div#results-container ol.search-results li.mod.result.job')

    for li in lis:
      try:
        company_title = li.find_element_by_css_selector('div.description bdi a').get_attribute('innerHTML')
        location = li.find_element_by_css_selector('dl.demographic dd.separator bdi').get_attribute('innerHTML')
        ad = strip_tags(time+SEPARATOR+company_title+SEPARATOR+'URL'+SEPARATOR+location).encode("utf8")
        self.log('measurement', 'ad', ad)
      except NoSuchElementException:
        pass 
开发者ID:tadatitam,项目名称:info-flow-experiments,代码行数:20,代码来源:linkedin_ads.py

示例4: go_to_category

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def go_to_category(self, category_name):
        """Clicks appropriate button in the navigation drawer."""
        self.driver.find_element_by_accessibility_id(self.NAV_DRAWER_TOGGLE_ID).click()
        sleep(self.NAV_DRAWER_ANIMATION_DELAY)

        category_element = None
        num_attempts = 0

        while category_element is None and num_attempts < self.MAX_ATTEMPTS:
            try:
                category_element = self.driver.find_element_by_name(category_name)
                num_attempts += 1
            except NoSuchElementException:
                self.scroll_nav_drawer_down()

        category_element.click() 
开发者ID:aws-samples,项目名称:aws-device-farm-appium-python-tests-for-android-sample-app,代码行数:18,代码来源:navigation_page.py

示例5: __find_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def __find_element(self, elem):
        """
        Find if the element exists.
        """
        for i in range(self.timeout):
            elems = Browser.driver.find_elements(by=elem[0], value=elem[1])
            if len(elems) == 1:
                logging.info("✅ Find element: {by}={value} ".format(
                    by=elem[0], value=elem[1]))
                break
            elif len(elems) > 1:
                logging.info("❓ Find {n} elements through: {by}={value}".format(
                    n=len(elems), by=elem[0], value=elem[1]))
                break
            else:
                sleep(1)
        else:
            error_msg = "❌ Find 0 elements through: {by}={value}".format(by=elem[0], value=elem[1])
            logging.error(error_msg)
            raise NoSuchElementException(error_msg) 
开发者ID:SeldomQA,项目名称:poium,代码行数:22,代码来源:page_objects.py

示例6: setup_class

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def setup_class(self):
        """
        Setup: Open a mozilla browser, login
        """
        self.browser = Firefox()
        self.browser.get('http://localhost:5000/')
        token = self.browser.find_element_by_name("token")
        password = "foo"
        # login
        token.send_keys(password)
        token.send_keys(Keys.ENTER)
        time.sleep(.1)
        try:
            self.browser.find_element_by_xpath("//input[@value='Logout']")
        except NoSuchElementException:
            raise ValueError("Can't login!!! Create a user 'foo' with the permissions"
                             "'read' and 'create' in your PERMISSIONS in the config") 
开发者ID:bepasty,项目名称:bepasty-server,代码行数:19,代码来源:test_website.py

示例7: send_message

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def send_message(self, name, message):
        message = self.emojify(message)  # this will emojify all the emoji which is present as the text in string
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(name+Keys.ENTER)  # we will send the name to the input key box
        try:
            send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
            messages = message.split("\n")
            for msg in messages:
                send_msg.send_keys(msg)
                send_msg.send_keys(Keys.SHIFT+Keys.ENTER)
            send_msg.send_keys(Keys.ENTER)
            return True
        except TimeoutException:
            raise TimeoutError("Your request has been timed out! Try overriding timeout!")
        except NoSuchElementException:
            return False
        except Exception:
            return False

    # This method will count the no of participants for the group name provided 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:23,代码来源:whatsapp.py

示例8: get_last_seen

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def get_last_seen(self, name, timeout=10):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(name+Keys.ENTER)  # we will send the name to the input key box
        last_seen_css_selector = "._315-i"
        start_time = dt.datetime.now()
        try:
            WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                (By.CSS_SELECTOR, last_seen_css_selector)))
            while True:
                last_seen = self.browser.find_element_by_css_selector(last_seen_css_selector).text
                if last_seen and "click here" not in last_seen:
                    return last_seen
                end_time = dt.datetime.now()
                elapsed_time = (end_time-start_time).seconds
                if elapsed_time > 10:
                    return "None"
        except TimeoutException:
            raise TimeoutError("Your request has been timed out! Try overriding timeout!")
        except NoSuchElementException:
            return "None"
        except Exception:
            return "None"

    # This method does not care about anything, it sends message to the currently active chat
    # you can use this method to recursively send the messages to the same person 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:27,代码来源:whatsapp.py

示例9: lagou_filter

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def lagou_filter(browser, job_list, company_name, job_filter):
    '''filter by job types'''
    while True:
        lagou_page(browser, job_list, company_name, job_filter)
        #check next page
        try:
            pages = browser.find_element_by_class_name('pages')
            spans = pages.find_elements_by_tag_name('span')
            span = get_next_span(spans)
            if span:
                span.click()
                time.sleep(SLEEPTIME)
            else:
                return
        except NoSuchElementException as _e:
            print(_e)
            return 
开发者ID:9468305,项目名称:python-script,代码行数:19,代码来源:lagou.py

示例10: scrape_page

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def scrape_page(self):
        print("SCRAPING PAGE: ", self.page_num)
        self.scroll_to_bottom()
        try:
            next_btn = self.driver.find_element_by_css_selector('button.next')
        except NoSuchElementException:
            next_btn = None
        connections = self.driver.find_elements_by_css_selector(
            '.search-entity')
        results = []
        for conn in connections:
            result = {}
            result['name'] = conn.find_element_by_css_selector(
                '.actor-name').text
            link = conn.find_element_by_css_selector(
                '.search-result__result-link').get_attribute('href')
            user_id = re.search(r'/in/(.*?)/', link).group(1)
            result['id'] = user_id
            results.append(result)
        return bool(next_btn), results 
开发者ID:austinoboyle,项目名称:scrape-linkedin-selenium,代码行数:22,代码来源:ConnectionScraper.py

示例11: __wait_for_appearing

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [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 
开发者ID:hw712,项目名称:knitter,代码行数:25,代码来源:webelement.py

示例12: __wait_for_disappearing

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [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 
开发者ID:hw712,项目名称:knitter,代码行数:25,代码来源:webelement.py

示例13: web_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def web_element(self):
        """Find WebElement using element locator

        :returns: web element object
        :rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
        """
        try:
            self._find_web_element()
        except NoSuchElementException as exception:
            parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''
            msg = "Page element of type '%s' with locator %s%s not found"
            self.logger.error(msg, type(self).__name__, self.locator, parent_msg)
            exception.msg += "\n  {}".format(msg % (type(self).__name__, self.locator, parent_msg))
            raise exception
        return self._web_element 
开发者ID:Telefonica,项目名称:toolium,代码行数:17,代码来源:page_element.py

示例14: is_present

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def is_present(self):
        """Find element and return True if it is present

        :returns: True if element is located
        """
        try:
            # Use _find_web_element() instead of web_element to avoid logging error message
            self._web_element = None
            self._find_web_element()
            return True
        except NoSuchElementException:
            return False 
开发者ID:Telefonica,项目名称:toolium,代码行数:14,代码来源:page_element.py

示例15: test_is_present_not_found

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import NoSuchElementException [as 别名]
def test_is_present_not_found(driver_wrapper):
    driver_wrapper.driver.find_element.side_effect = NoSuchElementException('Unknown')

    assert RegisterPageObject(driver_wrapper).username.is_present() is False 
开发者ID:Telefonica,项目名称:toolium,代码行数:6,代码来源:test_page_element.py


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