How to use the selenium.common.exceptions.NoSuchElementException function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github audax / pypo / functional_tests / test_functional.py View on Github external
# he opens the invite-page
        self.b.get(self.live_server_url+'/invite')

        # sees both codes
        self.assertEqual(codes, [c.text for c in self.b.find_elements_by_class_name('invite_code')])

        # and deletes the first code
        self.b.find_element_by_id('id_delete_code_{}'.format(valid_code.id)).submit()

        # now only the expired code is left
        self.assertEqual([expired_code.code],
                         [c.text for c in self.b.find_elements_by_class_name('invite_code')])

        # which he can't delete
        with self.assertRaises(NoSuchElementException):
            self.b.find_element_by_class_name('delete_code')
github mozilla / spade / vendor / django / contrib / admin / tests.py View on Github external
def get_select_option(self, selector, value):
        """
        Returns the <option> with the value `value` inside the <select> widget
        identified by the CSS selector `selector`.
        """
        from selenium.common.exceptions import NoSuchElementException
        options = self.selenium.find_elements_by_css_selector('%s &gt; option' % selector)
        for option in options:
            if option.get_attribute('value') == value:
                return option
        raise NoSuchElementException('Option "%s" not found in "%s"' % (value, selector))
</select></option>
github freenas / webui / tests / serv_lldp.py View on Github external
def is_element_present(self, how, what):
        """
        Helper method to confirm the presence of an element on page
        :params how: By locator type
        :params what: locator value
        """
        try: driver.find_element(by=how, value=what)
        except NoSuchElementException: return False
        return True
github freenas / webui / tests / selenium / theme.py View on Github external
def is_element_present(self, how, what):
        """
        Helper method to confirm the presence of an element on page
        :params how: By locator type
        :params what: locator value
        """
        try: driver.find_element(by=how, value=what)
        except NoSuchElementException: return False
        return True
github meta-it / odooselenium / odooselenium / ui.py View on Github external
def wait_for_page_load(self, timeout=10):
        """Wait for full page load and assert new page has been loaded."""
        # Inspect initial state.
        try:
            initial_body = self.webdriver.find_element(By.XPATH, '//body')
        except NoSuchElementException:  # First load.
            initial_body = None

        # Yield (back to 'with' block, where user triggers page load).
        yield

        # Wait for body to change.
        ui.WebDriverWait(self.webdriver, timeout).until(
            expected_conditions.staleness_of(initial_body)
        )
github SKYNE0 / news-spider / News_Spider / spider / kr.py View on Github external
driver.implicitly_wait(30)
        try:
            news = {}
            news['url'] = url
            news['link'] = url
            news['author'] = u"36Kr"
            summary = driver.find_element_by_xpath('//div[1]/div/section[@class="summary"]').text
            news['title'] = driver.title + '\n' + summary + '........\n\n点击查看全部'
            news['cover'] = driver.find_element_by_xpath('//section[@class="textblock"]//span/img').get_attribute('src')
            news['labels'] = driver.find_element_by_xpath('//div/span[2]/abbr').text
            news['service'] = 'Article.AddArticle'
            driver.quit()
            if not news['cover']:
                news['cover'] = "https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/crop%3D78%2C0%2C853%2C563%3Bc0%3Dbaike92%2C5%2C5%2C92%2C30/sign=834223da8c18367ab9c6259d1344b3f8/86d6277f9e2f07081b2bc4f3e324b899a901f213.jpg"
                return news
        except NoSuchElementException as e:
            print ("Appear error url=", url, e)
            return None
github watsonmw / automated-pageloadmetrics / python / 5-har.py View on Github external
def wait_for(self, func, timeout):
        start_time = time.time()
        cur_time  = start_time
        while (cur_time - start_time &lt; timeout):
            try:
                return func()
            except(exceptions.NoSuchElementException):
                pass

            cur_time = time.time()
            time.sleep(0.2)

        raise Exception("Timed out looking for element after " + timeout + " seconds")
github mdrichardson / FUTpuppeteer / FUTpuppeteer / sbc.py View on Github external
try:
                obj.__click_element__(search_panel.find_element_by_xpath('.//div[3]/div[2]/div[3]/div/a'))  # Remove quality filter
            except ElementNotVisibleException:
                pass
        obj.__click_element__(search_panel.find_element_by_xpath('.//div[3]/div[2]/div[4]/div/a'))  # Remove position filter
        obj.__click_element__(search_panel.find_element_by_xpath(".//*[contains(text(), 'Search')]"))
        sleep(Global.small_min)
        results = obj.__get_class__('MyClubResults', as_list=False)
        if not results:
            multi_log(obj, 'Missing {} for SBC solution'.format(info.get_player_info(player_to_search, False)['name']))
            return False
        try:
            results.find_element_by_class_name('has-action').click()
            obj.__click_xpath__(".//*[contains(text(), 'Swap Player')]")
            return True
        except (TimeoutException, ElementNotVisibleException, NoSuchElementException):
            pass
        multi_log(obj, 'Missing {} for SBC solution'.format(info.get_player_info(player_to_search, False)['name']))
        return False
github watsonmw / automated-pageloadmetrics / python / 6-whitelist.py View on Github external
def wait_for(self, func, timeout):
        start_time = time.time()
        cur_time  = start_time
        while (cur_time - start_time &lt; timeout):
            try:
                return func()
            except(exceptions.NoSuchElementException):
                pass

            cur_time = time.time()
            time.sleep(0.2)

        raise Exception("Timed out looking for element after " + timeout + " seconds")